Home > Backend Development > PHP Tutorial > PHP implements rc4 encryption algorithm_PHP tutorial

PHP implements rc4 encryption algorithm_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:57:41
Original
1583 people have browsed it

php implements the rc4 encryption algorithm. The decryption method of this algorithm is to re-encrypt it once and then it can be restored

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] /*
* rc4 encryption algorithm
* $pwd key
* $data data to be encrypted
*/
function rc4 ($pwd, $data)//$pwd key $data needs to be encrypted 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;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363949.htmlTechArticlephp implements the rc4 encryption algorithm. The decryption method of this algorithm is to re-encrypt once to restore the Copy to Clipboard reference. Content: [www.veryhuo.com] /* * rc4 encryption algorithm * $pwd key *...
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template