class ScoreEncrypt {
public
static function Jiami($txt, $key = null) {
empty($key) && $key = SECURE_CODE;
//有mcrypt扩展时
if(function_exists('mcrypt_module_open')){
return
self::encrypt($txt, $key);
}
//无mcrypt扩展时
$chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_";
$nh =
rand(0, 64);
$ch =
$chars[$nh];
$mdKey =
md5($key.$ch);
$mdKey =
substr($mdKey, $nh % 8, $nh % 8 + 7);
$txt =
base64_encode($txt);
$tmp =
'';
$i =
0;
$j =
0;
$k =
0;
for($i = 0;
$i < strlen($txt); $i++) {
$k = $k ==
strlen($mdKey) ? 0 : $k;
$j = ($nh +
strpos($chars, $txt [$i]) + ord($mdKey[$k++])) % 64;
$tmp .=
$chars[$j];
}
return
$ch.$tmp;
}
public
static function Jiemi($txt, $key = null) {
empty($key) && $key = SECURE_CODE;
//有mcrypt扩展时
if(function_exists('mcrypt_module_open')){
return
self::decrypt($txt, $key);
}
//无mcrypt扩展时
$chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_";
$ch =
$txt[0];
$nh =
strpos($chars, $ch);
$mdKey =
md5($key.$ch);
$mdKey =
substr($mdKey, $nh % 8, $nh % 8 + 7);
$txt =
substr($txt, 1);
$tmp =
'';