Home >Backend Development >PHP Tutorial >Quick calculation method of addition, subtraction, multiplication and division. PHP implements rc4 encryption algorithm code.

Quick calculation method of addition, subtraction, multiplication and division. PHP implements rc4 encryption algorithm code.

WBOY
WBOYOriginal
2016-07-29 08:48:271048browse

Code

Copy code The code is as follows:


/*
* rc4 encryption algorithm
* $pwd key
* $data data to be encrypted
*/
function rc4 ($pwd, $data)/ /$pwd key $data needs to encrypt the string
{
$key[] ="";
$box[] ="";
$pwd_length = strlen($pwd);
$data_length = strlen($data) ;
for ($i = 0; $i < 256; $i++)
{
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $ i;
}
for ($j = $i = 0; $i < 256; $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;
}

The above introduces the quick calculation method of addition, subtraction, multiplication and division. PHP implements the rc4 encryption algorithm code, including the content of the quick calculation method of addition, subtraction, multiplication and division. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn