尝试解密 PHP PseudoCrypt 类
我正在尝试创建一种方法来反转 PseudoCrypt 脚本:http://blog.kevburnsjr。 com/php-unique-hash.在此代码中,它具有以下等式:
$dec = ($num * $prime)-floor($num * $prime/$ceil)*$ceil;
我已经能够获取除 $num 之外的每个变量。例如,采用以下数字:
$dec = 566201239;
$prime = 566201239;
$ceil = 916132832;
方程将如下所示:
566201239 = ($num * 566201239)-floor($num * 566201239/916132832)*916132832;
答案应该是 1。但是我还没有确定如何使方程 = $num。我想使用它在 URL 中创建的哈希值,然后解密该哈希值以在我的数据库中执行查询。
编辑:如果有更好的方法来创建唯一且几乎没有重复空间的哈希,我会对此持开放态度。
编辑:不知何故,我为 $dec 输入了错误的值。 编辑:用功能代码更新博客文章。
I am trying to create a way to reverse the PseudoCrypt script listed at: http://blog.kevburnsjr.com/php-unique-hash. In this code it has the following equation:
$dec = ($num * $prime)-floor($num * $prime/$ceil)*$ceil;
I have been able to get every variable except for the $num. For instance take the following numbers:
$dec = 566201239;
$prime = 566201239;
$ceil = 916132832;
The equation would then look like this:
566201239 = ($num * 566201239)-floor($num * 566201239/916132832)*916132832;
The answer should be 1. However I have not determined the way make the equation = $num. I am wanting to use the hash it creates in a URL, then decrypt the hash to perform queries in my database.
Edit: If there is a better way to create a hash that will be unique with very little room for duplication I would be open to that instead.
Edit: Somehow I put the wrong value in for $dec.
Edit: Blog posting updated with functioning code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于其作者将其称为哈希函数,因此我认为它无法“解密”。当搜索足够长的时间时,您会发现多个输入产生相同的哈希值,因此无法知道使用了哪一个。
As this is called a Hash function by its author, I do not think it can be 'decrypted'. When searching long enough, you will find multiple inputs that produce the same Hash, so there is no way to know wich one was used.
观察一下
与 (thing%ceil) 相同
其中 % 是模运算符(除法后的余数)。就你而言,
请注意,这始终在 0 和 $ceil-1 之间,因此 $dec 的值是
无法获得与$ceil 相等的have。另一方面,
对于给定的 0 到 $ceil-1 之间的 $dec,您可以有效地找到
$num 介于 0 和 $ceil-1 之间的解决方案。
(观察结果是,如果 $num 是一个解,则 $num+i*$ceil
对于任何 i 也是一个解决方案。)
以下是 $dec=42 的处理方法。
我们将使用 $ceil = 2^5 * 31^5 这一事实。该方程给出
首先我们求($num%2),换句话说,$num是奇数还是奇数
甚至。
我们对方程两边取模 2:
由于 2 整除 $ceil,所以右边是 ($num * 566201239)%2。如果
这必须是 0,$num 必须是偶数(因为 $prime 不是)。
因此,对于某些 $a,我们有 ($num = 2*$a) 和
除以2后得到
请注意,% 符号后面的部分也被除以 2。
我们继续取模 2。我们得到 $a 是奇数,即 $a
= 2*$b+1 对于一些 $b。
(我开始使用同余符号 ≡;用 x ≡ y % z 我的意思是
x%z = y%z)。
我们继续...
总结一下替换,请记住
顺便说一句,我们可以将方程中的 $prime 模 31^5 减少为
好吧(我们可以在每一步中继续将其减少当前模数,但是
谁在乎?):
我们可以看到乘数不是素数,但实际上它不是
事情。
现在我们看最后一个方程模 31。
在 3 模 31 的倍数查找表中,我们发现 $e^8 % 31,
或者$e=31*$f+8:
我们继续...
让我们再次减少乘数...
通过向后替换我们得到$h=31*15+19 = 484,$g=31*$h+17 =
15021,$f=31*$g+11 = 465662,$e=31*$f+8 = 14435530,$num=32*e+6
= 461936966。
剩下的只是检查结果:
哇! :-)
博客的人应该使用 md5。
Observe that
is the same as (thing%ceil)
where % is the modulo operator (remainder after division). In your case,
Note that this is always between 0 and $ceil-1, so the value $dec you
have, which is equal to $ceil, cannot be obtained. On the other hand,
for a given $dec between 0 and $ceil-1, you can efficiently find
a solution $num between 0 and $ceil-1.
(An observation is that if $num is a solution than $num+i*$ceil
for any i is a solution as well.)
Here is how you proceed for $dec=42.
We will use the fact that $ceil = 2^5 * 31^5. The equation thus gives
First let us find ($num%2), in other words, whether $num is odd or
even.
We take both sides of the equation modulo 2:
Since 2 divides $ceil, the right-hand side is ($num * 566201239)%2. If
this has to be 0, $num has to be even (since $prime is not).
We thus have ($num = 2*$a) for some $a and
after division by 2 we get
Note that the part after the % sign got divided by 2 as well.
We continue by taking this modulo 2. We get that $a is odd, i.e., $a
= 2*$b+1 for some $b.
(I started to use the congruence notation ≡; by x ≡ y % z I mean
x%z = y%z).
We continue...
To summarize the substitutions, recall that
By the way, we can reduce the $prime in the equation modulo 31^5 as
well (we could keep reducing it by the current modul in each step, but
who cares?):
We can see that the multiplier is not a prime, but in fact it does not
matter.
Now we look at the last equation modulo 31.
In a lookup table of multiples of 3 modulo 31 we find that $e≡8 % 31,
or that $e=31*$f+8:
and we go on...
Let us reduce the multiplier again...
and by backward substitution we get $h=31*15+19 = 484, $g=31*$h+17 =
15021, $f=31*$g+11 = 465662, $e=31*$f+8 = 14435530, $num=32*e+6
= 461936966.
It remains just to check the result:
Wow! :-)
The guy of the blog should have rather used md5.
感谢评论者 Padraig Kennedy 的帮助,该库已升级为支持可逆性
http://blog.kevburnsjr.com/php-unique-hash
Thanks to some help from commenter Padraig Kennedy, the library has been upgraded to support reversibility
http://blog.kevburnsjr.com/php-unique-hash