<?php
header("Content-type:text/html; charset=utf-8");
//定义常量
define('PDK', 'PDK123');
//加密函数
function encrypt($code, $safe = true){
if($safe) $code = base64_encode(strrev(str_rot13($code)));
$code = (string)$code;
$code_length = strlen($code);
$md = md5(PDK);
$md_length = strlen($md);
$a=0;
while ($a <$code_length){
@$str .= sprintf ("%'02s",base_convert(ord($code{$a})+ord($md{$md_length % ($a+1)}),10,32));
$a++;
}
return $str;
}
//解密函数
function decrypt($code, $safe = true){
preg_match_all("/.{2}/", $code, $arr);
$arr = $arr[0];
$md = md5(PDK);
$md_length = strlen($md);
$a = 0;
foreach ($arr as $value){
@$str .= chr(base_convert($value,32,10)-ord($md{$md_length % ($a+1)}));
$a++;
}
if ($safe) $str = str_rot13(strrev(base64_decode($str)));
return $str;
}
?>
加密和解密函数
最新推荐文章于 2023-05-21 23:15:00 发布