in reply to Enrypt/decrypt module built in pure perl

Here is a pure Perl RC4, that I wrangled from some old Perl4 code. Making it work on strings and writing to variables is up to you.
#!/usr/bin/perl -0777 -- # $0 key infile > outfile # symmetric works both ways use strict; use warnings; my @k = map { ord($_) } split //, shift; my ( @s, $x, $y ); $y = 0; for ( my @t = @s = 0 .. 255 ) { $y = ( $k[ $_ % @k ] + $s[ $x = $_ ] + $y ) % 256; &S; } $x = $y = 0; for ( unpack( 'C*', <> ) ) { $x++; $y = ( $s[ $x %= 256 ] + $y ) % 256; &S; print pack( 'C', $_ ^= $s[ ( $s[$x] + $s[$y] ) % 256 ] ); } sub S { @s[ $x, $y ] = @s[ $y, $x ] }

I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness

Replies are listed 'Best First'.
Re^2: Enrypt/decrypt module built in pure perl
by libvenus (Sexton) on Feb 27, 2009 at 13:30 UTC

    This looks Neat, Thanks Guys !!