尝试解密 PHP PseudoCrypt 类

发布于 2024-10-31 08:31:52 字数 669 浏览 0 评论 0原文

我正在尝试创建一种方法来反转 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独陪着我 2024-11-07 08:32:05

由于其作者将其称为哈希函数,因此我认为它无法“解密”。当搜索足够长的时间时,您会发现多个输入产生相同的哈希值,因此无法知道使用了哪一个。

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.

葵雨 2024-11-07 08:32:03

观察一下

东西 - 地板(东西/天花板)*天花板

与 (thing%ceil) 相同
其中 % 是模运算符(除法后的余数)。就你而言,

$dec = ($num * $prime) % $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 这一事实。该方程给出

42 = ($num * 566201239) % (2^5 * 31^5)

首先我们求($num%2),换句话说,$num是奇数还是奇数
甚至。
我们对方程两边取模 2:

0 = 42 % 2 = (($num * 566201239) % (2^5*31^5)) % 2。

由于 2 整除 $ceil,所以右边是 ($num * 566201239)%2。如果
这必须是 0,$num 必须是偶数(因为 $prime 不是)。
因此,对于某些 $a,我们有 ($num = 2*$a) 和

2*21 = 42 = (2 * $a * 566201239) % (2^5 * 31^5),

除以2后得到

21 = ($a * 566201239) % (2^4 * 31^5)。

请注意,% 符号后面的部分也被除以 2。
我们继续取模 2。我们得到 $a 是奇数,即 $a
= 2*$b+1 对于一些 $b。

21 = ((2*$b+1) * 566201239) % (2^4 * 31^5),

349931614 = 21-566201239 = (2*$b * 566201239) % (2^4 * 31^5),

(我开始使用同余符号 ≡;用 x ≡ y % z 我的意思是
x%z = y%z)。

174965807 == ($b * 566201239) % (2^3 * 31^5)

我们继续...

174965807 = ((2*$c+1) * 566201239) % (2^3 * 31^5)

174965807 - 566201239 ≡ (2*$c * 566201239) % (2^3 * 31^5)

66830984 = 2*$c * 566201239) % (2^3 * 31^5)

33415492 = ($c * 566201239) % (2^2 * 31^5)

33415492 = (2*$d * 566201239) % (2^2 * 31^5)

16707746 = ($d * 566201239) % (2 * 31^5)

16707746 = (2*$e * 566201239) % (2 * 31^5)

8353873 = ($e * 566201239) % (31^5)。

总结一下替换,请记住

$num = 2*$a = 2*(2*$b+1) = 4*$b+2 = 4*(2*$c+1)+2 = 8*$c+6 = 8 *2*$d+6 =
8*2*2*$e+6 = 32*$e + 6

顺便说一句,我们可以将方程中的 $prime 模 31^5 减少为
好吧(我们可以在每一步中继续将其减少当前模数,但是
谁在乎?):

8353873 = ($e * 22247370) % (31^5)。

我们可以看到乘数不是素数,但实际上它不是
事情。

现在我们看最后一个方程模 31。

8353873 = ($e * 22247370) % (31^5)。

24 = 8353873 = ($e * 22247370) % (31^5) = ($e*22247370)
== ($e*3) % 31

在 3 模 31 的倍数查找表中,我们发现 $e^8 % 31,
或者$e=31*$f+8:

8353873 = ((31*$f+8) * 22247370) % (31^5)。

8353873 - 8*22247370 ≡ (31*$f*22247370) % (31^5)。

2149819 = 8353873 - 8*22247370 = (31*$f*22247370) % (31^5)。

69349 = 2149819/31 ≡ ($f*22247370) % (31^4)

我们继续...

2 = 69349 % 31 = ($f*22247370) % (31^4) = ($f*3) % 31

$f = 11 % 31

$f = 31*$g + 11

69349 = ((31*$g+11)*22247370) % (31^4)

81344 = 69349 - 11*22247370 = (31*$g*22247370) % (31^4)

2624 = ($g*22247370) % (31^3)

让我们再次减少乘数...

2624 = ($g*23284) % (31^3)

20 = 2624 = ($g*23284) % (31^3) = ($g*3) % 31

$g = 31*$h+17

2624 = ((31*$h+17)*23284) % (31^3)

23870 = 2624 - 17*23284 = (31*$h*23284) % (31^3)

770 = ($h*23284) % (31^2)

26 = 770 = ($h*23284) % (31^2) = ($h*3) % 31

$h = 31*$i + 19

770 = ((31*$i+19)*23284) % (31^2)

434 = 770 - 19*23284 = (31*$i*23284) % (31^2)

14 = ($i*3) % 31

$i = 15

通过向后替换我们得到$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。

剩下的只是检查结果:

.>>> (461936966*566201239)%916132832

42

哇! :-)

博客的人应该使用 md5。

Observe that

thing - floor(thing/ceil)*ceil

is the same as (thing%ceil)
where % is the modulo operator (remainder after division). In your case,

$dec = ($num * $prime) % $ceil

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

42 = ($num * 566201239) % (2^5 * 31^5)

First let us find ($num%2), in other words, whether $num is odd or
even.
We take both sides of the equation modulo 2:

0 = 42 % 2 = (($num * 566201239) % (2^5*31^5)) % 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

2*21 = 42 = (2 * $a * 566201239) % (2^5 * 31^5),

after division by 2 we get

21 = ($a * 566201239) % (2^4 * 31^5).

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.

21 = ((2*$b+1) * 566201239) % (2^4 * 31^5),

349931614 ≡ 21-566201239 ≡ (2*$b * 566201239) % (2^4 * 31^5),

(I started to use the congruence notation ≡; by x ≡ y % z I mean
x%z = y%z).

174965807 ≡ ($b * 566201239) % (2^3 * 31^5)

We continue...

174965807 ≡ ((2*$c+1) * 566201239) % (2^3 * 31^5)

174965807 - 566201239 ≡ (2*$c * 566201239) % (2^3 * 31^5)

66830984 ≡ 2*$c * 566201239) % (2^3 * 31^5)

33415492 ≡ ($c * 566201239) % (2^2 * 31^5)

33415492 ≡ (2*$d * 566201239) % (2^2 * 31^5)

16707746 ≡ ($d * 566201239) % (2 * 31^5)

16707746 ≡ (2*$e * 566201239) % (2 * 31^5)

8353873 ≡ ($e * 566201239) % (31^5).

To summarize the substitutions, recall that

$num = 2*$a = 2*(2*$b+1) = 4*$b+2 = 4*(2*$c+1)+2 = 8*$c+6 = 8*2*$d+6 =
8*2*2*$e+6 = 32*$e + 6

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?):

8353873 ≡ ($e * 22247370) % (31^5).

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.

8353873 ≡ ($e * 22247370) % (31^5).

24 ≡ 8353873 ≡ ($e * 22247370) % (31^5) ≡ ($e*22247370)
≡ ($e*3) % 31

In a lookup table of multiples of 3 modulo 31 we find that $e≡8 % 31,
or that $e=31*$f+8:

8353873 ≡ ((31*$f+8) * 22247370) % (31^5).

8353873 - 8*22247370 ≡ (31*$f*22247370) % (31^5).

2149819 ≡ 8353873 - 8*22247370 ≡ (31*$f*22247370) % (31^5).

69349 = 2149819/31 ≡ ($f*22247370) % (31^4)

and we go on...

2 ≡ 69349 % 31 ≡ ($f*22247370) % (31^4) ≡ ($f*3) % 31

$f ≡ 11 % 31

$f = 31*$g + 11

69349 ≡ ((31*$g+11)*22247370) % (31^4)

81344 ≡ 69349 - 11*22247370 ≡ (31*$g*22247370) % (31^4)

2624 ≡ ($g*22247370) % (31^3)

Let us reduce the multiplier again...

2624 ≡ ($g*23284) % (31^3)

20 ≡ 2624 ≡ ($g*23284) % (31^3) = ($g*3) % 31

$g = 31*$h+17

2624 ≡ ((31*$h+17)*23284) % (31^3)

23870 ≡ 2624 - 17*23284 ≡ (31*$h*23284) % (31^3)

770 ≡ ($h*23284) % (31^2)

26 ≡ 770 ≡ ($h*23284) % (31^2) = ($h*3) % 31

$h = 31*$i + 19

770 ≡ ((31*$i+19)*23284) % (31^2)

434 ≡ 770 - 19*23284 ≡ (31*$i*23284) % (31^2)

14 = ($i*3) % 31

$i = 15

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:

.>>> (461936966*566201239)%916132832

42

Wow! :-)

The guy of the blog should have rather used md5.

听风吹 2024-11-07 08:31:56

感谢评论者 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文