专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » 加密算法:php的几种加密算法 »正文

加密算法:php的几种加密算法

来源: 发布时间:星期三, 2008年9月10日 浏览:80次 评论:0
des加密解密算法:

rc4加密解密算法:

example1:

<?php

function authcode($string,$operation,$key = \'\') {

$key = md5($key);
$key_length = strlen($key);

$string = base64_decode($string);
$string_length = strlen($string);

$rndkey = $box = array();
$result = \'\';

for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($key[$i % $key_length]);
$box[$i] = $i;
}

for($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}

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($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
}

return str_replace(\'=\', \'\', base64_encode($result));


}

echo authcode(\"1238951230efff\",\"DECODE\",\"123qwedwe65ddd\");//加密
echo \"<br>\";
echo authcode(\"C4gIHousaRbf0g\",\"DECODE\",\"123qwedwe65ddd\");//解密

?>

example1 也是discuz的cookie加密的算法,如果按照rc4加解密算法的话应该可以解出,但是我在测试过程中发现有时候会有误差不是特别准确。有经验的朋友给指点一下!谢谢!

相关文章

读者评论

  • 共0条 分0页

发表评论

  • 昵称:
  • 内容: