Crypto - Many Xor Shift
Memories of long long ago. - KowerKoint
Last updated
Memories of long long ago. - KowerKoint
Last updated
I couldn't solve this during the CTF, but found the concept interesting.
The xor_shift() takes an input state and shifts the state upwards by one and adds a new state. We can express the state shift in the form of matrices.
Let Un and Ln be the left and right shift matrices respectively such that
If we use GF(2) as our base ring, then we can define xor as addition.
First, let's see what new state is being added
Let U be the left shift matrix and L be the right shift matrix
Then t can be represented as follows
Then we can express the new state as
The reason for doing this is to express the state in a linear combination of s6 and s0, which makes it easier to design the matrix
We need to construct a matrix such that it takes (s0,s1,s2,s3,s4,s5,s6) and outputs (s1,s2,s3,s4,s5,s6, A*Z*s0 + s6*Y)
For convenience, I add A*s0 to start of the state so that the matrix multiplication comes out nicely
We then compare this with the xor_shift function to check if it works
A variant of this method was most likely used by the authors to encrypt
We use the same idea, except we construct a different matrix to switch the input and output state. To make it easier, we multiply by another matrix first to make it easier to deal with the last element
Code to generate the matrix
Code to generate the matrix
Now that we have everything that we need, we can finally decrypt
This challenge uses xor shifts to encrypt the flag. Before proceeding with the writeup, I highly recommend reading , as I use the code as well as the concepts explained there.