php的几种加密算法

来源:互联网 发布:linux下apache配置文件 编辑:程序博客网 时间:2024/06/10 09:05



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加解密算法的话应该可以解出,但是我在测试过程中发现有时候会有误差不是特别准确。有经验的朋友给指点一下!谢谢!

目前整理中,有兴趣的朋友希望能够给点补充!