浏览代码

fix #1141 修复mac_alphaID加密碰撞问题

magicblack 6 月之前
父节点
当前提交
5cbf764962
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5 5
      application/common.php

+ 5 - 5
application/common.php

@@ -1733,12 +1733,12 @@ function mac_alphaID($in, $to_num=false, $pad_up=false, $passKey='')
             }
         }
         $out = "";
-        for ($t = floor(log10($in) / log10($base)); $t >= 0; $t--) {
-            $a = floor($in / bcpow($base, $t));
-            $out = $out . substr($key, $a, 1);
-            $in = $in - ($a * bcpow($base, $t));
+        // 修复部分:改用逐位计算代替浮点运算
+        while ($in > 0) {
+            $remainder = $in % $base;
+            $out = substr($key, $remainder, 1) . $out;
+            $in = ($in - $remainder) / $base;
         }
-        $out = strrev($out);
     }
     return $out;
 }