/**
* 加密数字方法
* echo idEncode(222);
* @author uuleaf[<uuleaf#163.com>] 小叶
* @param int $int 要加密的数字
* @return string 加密后的字符串
*/
function idEncode($int)
{
$str = md5($int);
$sarr = str_split($str);
$stai = (ord($str) + 8) % 10;
if ($stai == 0) $stai = 8;
$idstr = base_convert($int * $stai, 10, 32);
$str1 = substr($str, 10, 2);
$str2 = substr($str, 14, 2);
$str3 = substr($str, 18, 2);
return $str1 . $idstr . $str2 . $stai . $str3;
}
/**
* 解密数字方法
* echo idDncode("");
* @author uuleaf[<uuleaf#163.com>] 小叶
* @param string $str 要解密的数字
* @return int 解密后的数字
*/
function idDecode($str)
{
$idstr = substr(substr($str, 2), 0, -5);
$ji = base_convert($idstr, 32, 10);
$si = (int)substr($str, -3, -2);
return floor($ji / $si);
}
$id =
55265896;
echo "加密前的网址:
http://youkuaiyun.com/blog-{$id}.html";
echo "\n";
$encode_str = idEncode($id);
echo "加密后的网址:
http://youkuaiyun.com/blog-{$encode_str}.html";
echo "\n";
$decode_str = idDecode($encode_str);
echo "还原后的网址:
http://youkuaiyun.com/blog-{$decode_str}.html";
本文介绍了一种数字加密及解密的方法,包括加密过程和解密过程,并通过实例展示了如何使用该方法对数字进行加密和解密。加密方法利用MD5算法生成字符串,再通过特定算法处理得到加密后的字符串;解密过程则根据加密字符串还原原始数字。
2921

被折叠的 条评论
为什么被折叠?



