Last active
March 17, 2016 06:10
-
-
Save shoghicp/a3896c38f4c332430816 to your computer and use it in GitHub Desktop.
RC4 implementation in PHP, without run-time notices or errors. Outputs keystream directly. http://en.wikipedia.org/wiki/RC4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
for($K='Key',$_=range($i=$j=0,$n=255);$i<=$n;$j+=$_[$i]+ord($K{$i%strlen($K)}),_($_[$j&=$n],$_[$i++])); | |
for($j=$i=0;++$i;$j+=$_[$i&=$n],_($_[$j&=$n],$_[$i]),printf('%x',$_[($_[$i]+$_[$j])&$n])); | |
function _(&$i,&$j){$i=$j+$i-($j=$i);} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php for($K='Key',$_=range($i=$j=0,$n=255);$i<=$n;$j+=$_[$i]+ord($K{$i%strlen($K)}),_($_[$j&=$n],$_[$i++]));for($j=$i=0;++$i;$j+=$_[$i&=$n],_($_[$j&=$n],$_[$i]),printf('%c',$_[($_[$i]+$_[$j])&$n]));function _(&$i,&$j){$i=$j+$i-($j=$i);} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
for( | |
$K = 'Key', | |
$_ = range($i = $j = 0, $n = 255); | |
$i <= $n; | |
$j += $_[$i] + ord($K{$i % strlen($K)}), | |
_($_[ | |
$j &= $n | |
], $_[ | |
$i++ | |
]) | |
); | |
for($j = $i = 0; | |
++$i; | |
$j += $_[ | |
$i &= $n | |
], | |
_($_[ | |
$j &= $n | |
], $_[$i]), | |
printf('%x', $_[ | |
($_[$i] + $_[$j]) & $n | |
]) | |
); | |
function _(&$i, &$j){ | |
$i = $j + $i - ($j = $i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment