Code
Copy CodeThe code is as follows:
/*
* RC4 encryption algorithm
* $pwd Key
* $data the data to be encrypted
*/
function RC4 ($pwd, $data)//$pwd key $data need to encrypt string
{
$key [] = "";
$box [] = "";
$pwd _length = strlen ($PWD);
$data _length = strlen ($data);
for ($i = 0; $i < $i + +)
{
$key [$i] = Ord ($pwd [$i% $pwd _length]);
$box [$i] = $i;
}
for ($j = $i = 0; $i <; $i + +)
{
$j = ($j + $box [$i] + $key [$i])% 256;
$tmp = $box [$i];
$box [$i] = $box [$j];
$box [$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data _length; $i + +)
{
$a = ($a + 1)% 256;
$j = ($j + $box [$a])% 256;
$tmp = $box [$a];
$box [$a] = $box [$j];
$box [$j] = $tmp;
$k = $box [(($box [$a] + $box [$j])% 256)];
$cipher. = Chr (ord ($data [$i]) ^ $k);
}
return $cipher;
}
http://www.bkjia.com/PHPjc/325314.html www.bkjia.com true http://www.bkjia.com/PHPjc/325314.html techarticle Code Copy Code code is as follows:/* * RC4 encryption Algorithm * $PWD key * $data The data to be encrypted */function RC4 ($pwd, $data)//$pwd key $data need to encrypt the string {$key [] = ""; $b ox[ ...