Also, is there a way to get this approach to work with an arbitrary length plaintext? I.e. with plaintexts more than 16 character in length?
# Encrypter use Crypt::Blowfish (); use MIME::Base64 qw( encode_base64 ); my $key = ...; my $plaintext = ...; die("Text to encrypt must be less than 16 bytes long\n") if length($plaintext) >= 16; my $cipher = Crypt::Blowfish->new($key); my $padded_plaintext = pack('Ca15', length($plaintext), $plaintext); my $ciphertext1 = $cipher->encrypt(substr($padded_plain +text, 0, 8)); my $ciphertext2 = $ciphertext1 ^ $cipher->encrypt(substr($padded_plain +text, 8, 8)); my $ciphertext = $ciphertext1 . $ciphertext2; my $websafe_ciphertext = substr(encode_base64($ciphertext, ''), 0, -2) +; # Decrypter use Crypt::Blowfish (); use MIME::Base64 qw( decode_base64 ); my $key = ...; my $websafe_ciphertext = ...; die("Text to decrypt must be exactly 22 bytes long\n") if length($websafe_ciphertext) != 22; my $cipher = Crypt::Blowfish->new($key); my $ciphertext = decode_base64($websafe_ciphertext.'=='); my $ciphertext1 = substr($ciphertext, 0, 8); my $ciphertext2 = substr($ciphertext, 8, 8); my $padded_plaintext = $cipher->decrypt( $ciphertext1) . $cipher->decrypt($ciphertext1 ^ $ciphertext2); my $plaintext = unpack('C/a*', $padded_plaintext);
In reply to Re^2: Short & Sweet Encryption?
by Anonymous Monk
in thread Short & Sweet Encryption?
by inblosam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |