Reverse function

时间:2016-05-11 11:30:48

标签: function assembly reverse-engineering

I have been trying to reverse a quite simple looking function. the function is presented in assembly: (Argument is loaded into AX)

AND AX, 0xFFFE (round down to even number)
MUL AX (Multiply AX by AX ; the result is represented as DX:AX)
XOR AX,DX

The function can be described as: H(X) = F(X & 0xFFFE); F(X) = ((X * X) mod 2^16) xor ((X * X) div 2^16)

Calculated all of the values from 1 to 2^16 and plotted on matlab in order to "see" some function.

enter image description here

Can anyone help me find an answer to this? (when given y what is the argument x). It might be that for some values there is more than one answer, so narrowing it down is my goal.

Thanks, Or.

1 个答案:

答案 0 :(得分:1)

它是hash function.
你不能反转哈希函数,因为它的全部意义在于它是一个单向函数。
乘法显然是可逆的,它不是xor。通过组合乘法的低部分和高部分,您将丢失信息。

正如您在图中看到的那样,有一些空格,因为该图中有2 ^ 16个空格,这意味着还有不同的输入值,这些值会散列到相同的值。
这在散列函数中很常见。

“扭转”的唯一方法。它是构建一个查找表,将输出值转换为可能的输入值。但是,您会发现每个输出值都是1个或更多输入值。

偶数x偶数始终是4的倍数 因此,低2位始终为0,因此结果的低2位是乘法的位16 + 17 位2..15是位2..15 xor位18..31的混合。
快速模拟显示24350个唯一输出ergo平均 1.34 0.34重复每个输入值,不错。
最大碰撞次数为6次,但大多数碰撞都没有发生碰撞。

对于所有不碰撞的数字,您可以在查找表中唯一地查找您的输入值(所有这些显然忽略奇数输入值)。