#!/usr/bin/perl

# RC4 in 146 bytes of code
#
# usage:  echo 'plain text' | rc4.pl hexkey > encrypted.file
#        or
#         cat /path/to/file | rc4.pl hexkey > encrypted.file
# e.g., echo testing | rc4.pl a0b1c2d3
#
# decrypting goes the same way
# e.g., cat encrypted.file | rc4.pl a0b1c2d3 > decrypted.file
#
# -samy [cp5@LucidX.com]

sub f{@s[$x,$y]=@s[($y+=$s[$x])%=@s,$x];$s[$x++]+$s[$y]-@s}@k=pop=~/../g;f$y+=hex$k[$x%@k]for@s=0..255;$x=1;$y=0;$/=\1;print$_^chr$s[f$x%=@s]for<>
