Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created March 25, 2012 00:51
Show Gist options
  • Save stefanocudini/2190466 to your computer and use it in GitHub Desktop.
Save stefanocudini/2190466 to your computer and use it in GitHub Desktop.
rc4 encode
<?
function encRC4($key, $text)
{
$kl=strlen($key);
$s=array();
for($i=0; $i<256; $i++)
$s[$i]=$i;
$y=0;
$x=$kl;
while($x--) {
$y=(charCodeAt($key,$x) + $s[$x] + $y) % 256;
$t=$s[$x]; $s[$x]=$s[$y]; $s[$y]=$t;
}
$x=0; $y=0;
$z="";
for($x=0; $x<strlen($text); $x++) {
$x2=$x & 255;
$y=( $s[$x2] + $y) & 255;
$t=$s[$x2]; $s[$x2]=$s[$y]; $s[$y]=$t;
$z .= chr( charCodeAt($text,$x) ^ $s[($s[$x2] + $s[$y]) % 256] );
}
return $z;
}//*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment