# Solve an equation with binary rotation and xor

i'm having fun solving equations in Python but i'm stuck somewhere... I simplified the system $$\begin{cases} 4 = rol(rol(a, 2) \oplus rol(a \oplus b, 2) \oplus c, 3) = rol(b, 5) \oplus rol(c, 3)\\ 6 = rol(c, 7) \oplus rol(b, 6) \end{cases}$$ to obtain $$\begin{cases} b = ror(4, 5) \oplus ror(c, 2)\\ c = ror(6, 7) \oplus ror(b, 1) \end{cases}$$ and then $$b = ror(4, 5) \oplus ror(6, 9) \oplus ror(b, 3) = ror(4, 5) \oplus ror(6, 1) \oplus ror(b, 3) = 140 \oplus ror(b, 3)$$ where $\oplus$ is a xor operation, $ror$ is a 8bit rotation to the right and $rol$ is a 8bit rotation to the left.

Does anyone knows how to solve this kind of equation ?

## 1 Answer

In fact it's pretty simple. Let's do this on 4 bits, and call each bit by a letter.$$b = 6 \oplus ror(b, 3)$$ means $$ABCD \oplus 0110 = BCDA$$ You then just need to xor bit by bit $b$ and $6$. Because $xor$ inverts if the second part is a $1$ and do nothing if $0$, we can say that : $$\begin{cases} A = B\\ B = \bar C\\ C = \bar D\\ D = A \end{cases}$$ There is two solutions to this :$$\begin{cases} A = 0\\ B = 0\\ C = 1\\ D = 0 \end{cases}$$ or $$\begin{cases} A = 1\\ B = 1\\ C = 0\\ D = 1 \end{cases}$$ So the equation $b = 6 \oplus ror(b, 3)$ has two solutions : $$b = \{2, 13\}$$ We can observe that there will always be an even number of solutions which are binary opposite two by two.