Problems with RC5 (looks simple enough)
[email protected] (John Francis) Thu, 11 Jul 2002 15:04:03 -0400 (EDT)
| Newsgroups | perl.crypto |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I do not understand why I am getting this problem. I encrypt the
contents of the file with $key, and decrypt it with $key as well. When I
print out the results, I get garbage on the screen.
#!/usr/bin/perl
use IO::Socket;
use Crypt::RC5;
#http://search.cpan.org/doc/SIFUKURT/Crypt-RC5-1.01/RC5.pm
$key = 'e726c4973ddd9c671cc07f8eef0f08b2';
$rc5 = new Crypt::RC5($key, '12' );
open(FILE,"/etc/passwd");
while(<FILE>){
$file .= $_;
}
close(FILE);
$stuffing = length($file)%8;
for($i = 0;$i<$stuffing;$i++){
$file .='#';
}
# Since RC5 takes word input of size 8, i stuff the data with
# pound signs to make sure it is properly sized
$cipher = $rc5->encrypt($file);
$plain = $rc5->decrypt($cipher);
$plain =~ s/\#+$//;
print $plain;