首页 » SEO优化 » rc4加密算法php技巧_PHP RC4算法

rc4加密算法php技巧_PHP RC4算法

访客 2024-11-09 0

扫一扫用手机浏览

文章目录 [+]

/

0 加密 1 解密

rc4加密算法php技巧_PHP RC4算法

@param $instr

rc4加密算法php技巧_PHP RC4算法
(图片来自网络侵删)

@param $operation

@param $expiry

@param $key

@return String

/

function _tool_rc4($instr, $operation = 1, $expiry = 0 ,$key = \"大众\"大众)

{

$instr = str_replace(array(\公众_\"大众,\"大众-\公众),array(\"大众+\"大众,\"大众/\"大众),$instr);

$ckey_length = 4;

$key = md5($key ? $key : '');

$keya = md5(substr($key, 0, 16));

$keyb = md5(substr($key, 16, 16));

$keyc = $ckey_length ? ($operation > 0 ? substr($instr, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

$cryptkey = $keya.md5($keya.$keyc);

$key_length = strlen($cryptkey);

$instr = $operation > 0 ? base64_decode(substr($instr, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($instr.$keyb), 0, 16).$instr;

$string_length = strlen($instr);

$result = '';

$box = range(0, 255);

$rndkey = array();

for($i = 0; $i <= 255; $i++) $rndkey[$i] = ord($cryptkey[$i % $key_length]);

for($j = $i = 0; $i < 256; $i++) {

$j = ($j + $box[$i] + $rndkey[$i]) % 256;

$tmp = $box[$i];

$box[$i] = $box[$j];

$box[$j] = $tmp;

}

unset($rndkey);

for($a = $j = $i = 0; $i < $string_length; $i++) {

$a = ($a + 1) % 256;

$j = ($j + $box[$a]) % 256;

$tmp = $box[$a];

$box[$a] = $box[$j];

$box[$j] = $tmp;

$result .= chr(ord($instr[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));

}

if($operation > 0) {

if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) return substr($result, 26);

return '';

}

return $keyc.str_replace(array(\"大众=\"大众,\"大众+\"大众,\公众/\公众),array(\公众\公众,\公众_\公众,\"大众-\公众), base64_encode($result));

}

//加密

$key = \"大众┬┭┮\"大众;

echo _tool_rc4(\公众小明:1344\"大众, 0, 0 ,$key);

//输出 445atmId_Nq-Og3g00CRw4s9LKcZKmIPqCfD-FYVGIug7H2IMDo

//解密

echo _tool_rc4(\公众445atmId_Nq-Og3g00CRw4s9LKcZKmIPqCfD-FYVGIug7H2IMDo\公众, 1, 0 ,$key);

//输出 小明:1344

PS:补图,上面的方便复制

标签:

相关文章

2020cl地址php技巧_CL建筑体系

随着节能标准的逐步提高,保温层的厚度显著增加,大量传统保温材料和施工工艺因受到限定而退出市场。CL建筑体系保温板的材质有多种选择,...

SEO优化 2024-12-10 阅读0 评论0