Dear fellow monks:

I am trying to develop a CGI sendable encryption scheme using blowfish to let CGI's talk to each other on different servers. Here is the question:

I use Crypt:Blowfish and a for loop to chop the string up into 8 byte pieces and feed them through the module.

my @textCharacters = split( // , $plainText ); for( $j = 0 ; $j <= ( length( $plainText )/8 )-1 ; $j++ ) { $z = ""; for( $k = 0 ; $k <= 7; $k++ ) { $i = $j*8 + $k; $z .= $textCharacters[$i]; } print "STRING"; print "Z = X $z X \n"; my $cipher = new Crypt::Blowfish $key; $cryptText .= $cipher->encrypt( $z ); }
This works fine save for the fact that get out many many "funky characters" such as :
7Æ Mb¢[ñF%L;Á^ô¥ X
These are making my telnet connection act odd as well as preventing the next step of the project which is remapping the chracterset of the Blowfish output into a simpler ( CGI Safe string ). I have that working for the ascii characters but not for the output characters that Blowfish puts out. I designed the remapping system to take the 256 chracters of the standard ASCII set:
my @glyphs; my $plainText = $_[0]; # Pad string to divisible by glyph choice my $padLength; if( length( $plainText ) % 3 ne "0" ) { $padLength = 3 - ( length( $plainText ) % 3 ); } $plainText .= " "x$padLength; print " pad = $padLength , $plainText X\n"; # Convert text to ASCII @asciiCodes = unpack( "c*", $plainText ); for( $j = 0 ; $j <= ( length( $plainText )/3 )-1 ; $j++ ) { my $sum = 0; for( $k = 0 ; $k <= 2 ; $k++ ) { $i = ( $j*3 + $k ); $sum += @asciiCodes[$i] * ( 65536 ** ( 2-$k ) ); } push( @glyphs , $sum ); } return( @glyphs );
and that will output a string of numbers that represent 4 characters. It does more after that but this is the start. The blowfish output characters causes this to return negative values. I though mabye that it is working on 16 bit characters like unicode does and I upped the alphabet size to 2^16 but I still get negative values.

Any ideas?


In reply to Blowfish Cypher by Angel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.