1function enToken($txt) { 2 $key = 'colin'; 3 $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-"; 4 $nh = rand(0, 64); 5 $ch = $chars[ $nh ]; 6 $mdKey = md5($key . $ch); 7 $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7); 8 $txt = base64_encode($txt); 9 $tmp = ''; 10 $k = 0; 11 for ($i = 0; $i < strlen($txt); $i++) { 12 $k = $k == strlen($mdKey) ? 0 : $k; 13 $j = ($nh + strpos($chars, $txt[ $i ]) + ord($mdKey[ $k++ ])) % 64; 14 $tmp .= $chars[ $j ]; 15 } 16 17 return urlencode($ch . $tmp); 18} 19 20function unToken($txt) { 21 $key = 'colin'; 22 $txt = urldecode($txt); 23 $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-"; 24 $ch = $txt[0]; 25 $nh = strpos($chars, $ch); 26 $mdKey = md5($key . $ch); 27 $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7); 28 $txt = substr($txt, 1); 29 $tmp = ''; 30 $k = 0; 31 for ($i = 0; $i < strlen($txt); $i++) { 32 $k = $k == strlen($mdKey) ? 0 : $k; 33 $j = strpos($chars, $txt[ $i ]) - $nh - ord($mdKey[ $k++ ]); 34 while ($j < 0) $j += 64; 35 $tmp .= $chars[ $j ]; 36 } 37 38 return base64_decode($tmp); 39}
PHP 加密解密
Wesley13
2021-10-11
1069 0 0
点赞
收藏
评论区
加载中...