18
This commit is contained in:
+28
-15
@@ -26,15 +26,40 @@ class Encrypt
|
||||
*/
|
||||
static function userIDencode($userID,$key=0):string{
|
||||
if(!is_numeric(($userID))){
|
||||
return $userID;
|
||||
return $userID.'';
|
||||
}
|
||||
$userID = intval($userID);
|
||||
if($userID<=100234){
|
||||
return $userID.'';
|
||||
}
|
||||
if($userID == '100235'){
|
||||
return 'JWrb5JPm3E';
|
||||
}
|
||||
if($userID<=102028){
|
||||
return id_encode($userID);
|
||||
}
|
||||
return self::intEncode($userID,$key);
|
||||
}
|
||||
/**
|
||||
* 解密非连续数字ID为原始连续ID
|
||||
* @param int $encryptedId 加密后的非连续ID(8位数)
|
||||
* @param int $userKey 可选的额外密钥
|
||||
* @return int 原始连续ID
|
||||
*/
|
||||
static function userIDDecode($userID,$key=0):string{
|
||||
if($userID == 'JWrb5JPm3E'){
|
||||
return '100235';
|
||||
}
|
||||
if(!is_numeric(($userID))){
|
||||
return id_decode($userID.'');
|
||||
}
|
||||
if($userID<=100234){
|
||||
return $userID.'';
|
||||
}
|
||||
|
||||
return self::intDecode($userID,$key);
|
||||
}
|
||||
static function intEncode($userID,$key=0){
|
||||
$key = intval($key);
|
||||
|
||||
$plainId = abs(intval($userID)) % self::$maxId;
|
||||
@@ -55,19 +80,8 @@ class Encrypt
|
||||
// 确保结果是8位数(10000000 - 99999999)
|
||||
return (self::$baseValue + $encrypted).'';
|
||||
}
|
||||
/**
|
||||
* 解密非连续数字ID为原始连续ID
|
||||
* @param int $encryptedId 加密后的非连续ID(8位数)
|
||||
* @param int $userKey 可选的额外密钥
|
||||
* @return int 原始连续ID
|
||||
*/
|
||||
static function userIDDecode($userID,$key=0):string{
|
||||
if(!is_numeric(($userID))){
|
||||
return id_decode($userID.'');
|
||||
}
|
||||
if($userID<=100234){
|
||||
return $userID.'';
|
||||
}
|
||||
static function intDecode($userID,$key=0): string{
|
||||
|
||||
$key = intval($key);
|
||||
// 去除基数,得到原始混淆值
|
||||
$cipherId = ($userID - self::$baseValue + self::$maxId) % self::$maxId;
|
||||
@@ -88,7 +102,6 @@ class Encrypt
|
||||
|
||||
return $plainId.'';
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用扩展欧几里得算法计算模逆元
|
||||
* 返回 x 使得 (a * x) % m = 1
|
||||
|
||||
Reference in New Issue
Block a user