首页 » Web前端 » phprc4算法技巧_PHP RC4算法

phprc4算法技巧_PHP RC4算法

duote123 2024-11-08 0

扫一扫用手机浏览

文章目录 [+]

/

0 加密 1 解密

phprc4算法技巧_PHP RC4算法

@param $instr

phprc4算法技巧_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:补图,上面的方便复制

标签:

相关文章

phppostzhuru技巧_sql注入具体介绍

SQL Injection:便是通过把SQL命令插入到Web表单递交或输入域名或页面要求的查询字符串,终极达到欺骗做事器实行恶意的...

Web前端 2024-12-10 阅读0 评论0

php输出cookie技巧_PHP Cookie

Cookie 是什么?cookie 常用于识别用户。cookie 是一种做事器留在用户打算机上的小文件。每当同一台打算机通过浏览器...

Web前端 2024-12-10 阅读0 评论0