home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / BubbleBabble.pm < prev    next >
Encoding:
Perl POD Document  |  2001-05-02  |  3.2 KB  |  106 lines

  1. package Digest::BubbleBabble;
  2. use strict;
  3.  
  4. use Exporter;
  5. use vars qw( @EXPORT_OK @ISA $VERSION );
  6. @ISA = qw( Exporter );
  7. @EXPORT_OK = qw( bubblebabble );
  8.  
  9. $VERSION = '0.01';
  10.  
  11. use vars qw( @VOWELS @CONSONANTS );
  12. @VOWELS = qw( a e i o u y );
  13. @CONSONANTS = qw( b c d f g h k l m n p r s t v z x );
  14.  
  15. sub bubblebabble {
  16.     my %param = @_;
  17.     my @dgst = map ord, split //, $param{Digest};
  18.     my $dlen = length $param{Digest};
  19.  
  20.     my $seed = 1;
  21.     my $rounds = ($dlen / 2) + 1;
  22.     my $retval = 'x';
  23.     for my $i (0..$rounds-1) {
  24.         if ($i+1 < $rounds || $dlen % 2) {
  25.             my $idx0 = ((($dgst[2 * $i] >> 6) & 3) + $seed) % 6;
  26.             my $idx1 = ($dgst[2 * $i] >> 2) & 15;
  27.             my $idx2 = (($dgst[2 * $i] & 3) + $seed / 6) % 6;
  28.             $retval .= $VOWELS[$idx0] . $CONSONANTS[$idx1] . $VOWELS[$idx2];
  29.             if ($i+1 < $rounds) {
  30.                 my $idx3 = ($dgst[2 * $i + 1] >> 4) & 15;
  31.                 my $idx4 = $dgst[2 * $i + 1] & 15;
  32.                 $retval .= $CONSONANTS[$idx3] . '-' . $CONSONANTS[$idx4];
  33.                 $seed = ($seed * 5 + $dgst[2 * $i] * 7 +
  34.                         $dgst[2 * $i + 1]) % 36;
  35.             }
  36.         }
  37.         else {
  38.             my $idx0 = $seed % 6;
  39.             my $idx1 = 16;
  40.             my $idx2 = $seed / 6;
  41.             $retval .= $VOWELS[$idx0] . $CONSONANTS[$idx1] . $VOWELS[$idx2];
  42.         }
  43.     }
  44.     $retval .= 'x';
  45.     $retval;
  46. }
  47.  
  48. 1;
  49. __END__
  50.  
  51. =head1 NAME
  52.  
  53. Digest::BubbleBabble - Create bubble-babble fingerprints
  54.  
  55. =head1 SYNOPSIS
  56.  
  57.     use Digest::BubbleBabble qw( bubblebabble );
  58.     use Digest::SHA1 qw( sha1 );
  59.  
  60.     my $fingerprint = bubblebabble( Digest => sha1($message) );
  61.  
  62. =head1 DESCRIPTION
  63.  
  64. I<Digest::BubbleBabble> takes a message digest (generated by
  65. either of the MD5 or SHA-1 message digest algorithms) and creates
  66. a fingerprint of that digest in "bubble babble" format.
  67. Bubble babble is a method of representing a message digest
  68. as a string of "real" words, to make the fingerprint easier
  69. to remember. The "words" are not necessarily real words, but
  70. they look more like words than a string of hex characters.
  71.  
  72. Bubble babble fingerprinting is used by the SSH2 suite
  73. (and, consequently, by I<Net::SSH::Perl>, the Perl SSH
  74. implementation) to display easy-to-remember key fingerprints.
  75. The key (a DSA or RSA key) is converted into a textual form,
  76. digested using I<Digest::SHA1>, and run through I<bubblebabble>
  77. to create the key fingerprint.
  78.  
  79. =head1 USAGE
  80.  
  81. I<Digest::BubbleBabble> conditionally exports one function called
  82. I<bubblebabble>; to import the function you must choose to
  83. import it, like this:
  84.  
  85.     use Digest::BubbleBabble qw( bubblebabble );
  86.  
  87. =head2 bubblebabble( Digest => $digest )
  88.  
  89. Currently takes only one pair of arguments, the key of
  90. which must be I<Digest>, the value of which is the actual
  91. message digest I<$digest>. You should generate this message
  92. digest yourself using either I<Digest::MD5> of I<Digest::SHA1>.
  93.  
  94. Returns the bubble babble form of the digest.
  95.  
  96. =head1 AUTHOR & COPYRIGHTS
  97.  
  98. Benjamin Trott, ben@rhumba.pair.com
  99.  
  100. Except where otherwise noted, Digest::BubbleBabble is Copyright
  101. 2001 Benjamin Trott. All rights reserved. Digest::BubbleBabble is
  102. free software; you may redistribute it and/or modify it under
  103. the same terms as Perl itself.
  104.  
  105. =cut
  106.