Re: Problems with RC5 (looks simple enough)
[email protected] (John Francis) Fri, 12 Jul 2002 15:35:13 -0400 (EDT)
| Newsgroups | perl.crypto |
|---|---|
| Message-ID | <[email protected]> |
Here is my script working perfectly after I applied Ben's patch.
#!/usr/bin/perl
use IO::Socket;
use Crypt::RC5;
$key = 'e726c4973ddd9c671cc07f8eef0f08b2';
$rc5 = Crypt::RC5->new( $key, '12');
open(FILE,"/etc/passwd");
while(<FILE>){
$file .= $_;
}
close(FILE);
$stuff = length($file)%8;
for($i=0;$i<$stuff;$i++){
$file .= '#';
}
$cipher = $rc5->encrypt($file);
$plain = $rc5->decrypt($cipher);
# I am not sure why, but there are extra ^@ characters at the end
# so i substitued everything after my # signs with nothing
$plain =~ s/(\#+.*)$//;
print $plain;
- John
On Fri, 12 Jul 2002, John Francis wrote:
> Benjamin,
> Thanks for the update, will definately try it out. However, the RC5
> problem doesnt just end with newlines, I think other non-alphanumeric
> characters cause problems as well. Also, I think this problems exists in
> implementations in other languages such as C. I was trying to do the same
> project in C but was getting similar problems, I ported over to Perl so
> that I would not have to deal with byte-by-byte problems. Thanks for all
> the help to all who provided the advise.
> - John
>
>
> On Fri, 12 Jul 2002, Benjamin Trott wrote:
>
> > > Yeah, I tried it on linux, and same problem. I don't think it handles
> > > newlines right.
> >
> > This patch fixes the newline bug:
> >
> > --- RC5.pm.orig Mon Nov 26 08:05:50 2001
> > +++ RC5.pm Fri Jul 12 11:18:31 2002
> > @@ -65,7 +65,7 @@
> > $A = Y( @S, 3 );
> > $B = Y( @L, M( $A + $B ) );
> > }
> > - while ( $text =~ /(.{8})/g ) {
> > + while ( $text =~ /(.{8})/gs ) {
> > $last = $';
> > Process( $1, $decrypt );
> > }
> >
> > bye,
> > Ben
> >
> >
>
>