Can this equation involving binary operations (XOR) and 32-bit integers be solved?

383 Views Asked by At

I need to solve the following equation for $x$:

$$y = (x * (z + A) + B) \oplus (x * z + C)$$

where:

  • $\oplus$ is the binary XOR operator for 32-bit integers
  • all variables are 32-bit integers
  • all variables except for $x$ are known
  • the variables $A$, $B$, and $C$ are the constants $32757935$, $-29408451$, and $-5512095$
  • EDIT: $z$ isn't a constant, and varies, but is unique for every pair of $x$ and $y$.

If it helps, this problem is based on/similar to this equation: How to solve this equation for $x$ with XOR involved?

1

There are 1 best solutions below

2
On

Note that the three operations $\oplus$, $\times$, and $+$ have the property that modification of the upper bits do not change the lower bits. That is if $\square$ is one of the three operations, $x \square y = z \mod 2^n$ will not change if you substitute $x$ with $x + 2^m$ for $m \geq n$.

So you can do a depth first search populating the lower bits first and checking the partial equality using a mask.

// TODO(yberman) do code

Note I suspect (but do not know) there is no closed form solution, as these operations don't play well together. IDEA uses a mixture of xor, multiply, and add for example. Even just addition and xor is mathematically messy if you allow rotations.