Samy Kamkar wrote: > > Hi everyone! Hello,
> Uri just pointed me out to this list today and I'm glad he did :) > > Well, I'd like to know if any of you are able to shorten this, I spent a > few minutes last night and this morning shortening it to 182 bytes and > I'm not sure what else can be done to it but I'm sure many of you here > will be able to shorten it a great deal > > It's RC4, so far in 182 bytes, accepts a hex key (e.g., a0b1c2) in > $ARGV[0] and reads input from <>: > sub > f{@s[$x,$y]=@s[$y,$x]}@k=map{hex}pop=~/../g;$y=($y+$k[$_%@k]+$s[$x=$_])%256,f > for@t=@s=0..255;$x=$y=0;$x++,$y+=$s[$x%=256]%256,f,print > chr($s[($s[$x]+$s[$y])%256]^ord)for<>=~/./g > > so: perl -e 'print"blah"' | perl -e '...' a0b1c2 > would print out the ASCII value of \xe8\x9c\xc0\xcb It should print out 0xe8 0x9c 0xcf 0x92 (which the C version does.) According to AC[1] the correct algorithm is: i = (i + 1) mod 256 j = (j + Si) mod 256 swap Si and Sj t = (Si + Sj) mod 256 K = St So change: $x++, $y += $s[ $x %= 256 ] % 256, To: $y = ($y + $s[ $x = ($x + 1) % 256 ]) % 256, John [1] Applied Cryptography, Bruce Schneier -- use Perl; program fulfillment