Home
Writeups Misc About
L-Win

L-Win

The challenge gives us a Fibonacci LFSR, with unknown taps, but we are provided 2048 bits of the output of LFSR. We have to first recover the taps, then from the taps we will recover the initial value.

To recover the taps from the given output, we can use the Berlekamp Massey algorithm. We are provided with 2048 bits, which is more than enough (we need more than 3842=768 bits). Sage has its own implementation of this algorithm, more information can be found here.

Instead of this approach, as we are provided with 2n bits of output (n=384), we can take on this challenge using an approach using an approach from an angle of linear equations. This is inspired from this blog entry (look at the "stupid" approach) and solving system of linear equations using matrices. Kudos to yassinebelarbi for helping me, I was stuck on this for 2 weeks.

First, xor operation is addition in GF(2). We can think of the Fibonacci LFSR, which uses the xor operation, as a linear combination of the bits. Denote the coefficients (taps) as c0,c1,c2,...,cn1. Denote the state as a0,a1,a2,...,an1.

Suppose the tap values are (0,5,15,16), c0=1,c5=1,c15=1,c16=1, and the other coefficient values are 0.

The output of the LFSR is the linear combination c0a0+c1a1+c2a2+...+cn1an1 in GF(2). The output of the linear combination will be an. Denote Sk=(ak,ak+1,ak+2,...,ak+n), the result of the linear combination of Sk and the coefficients is ak+n+1.

Since we know 2n bits, we know the output of the LFSR for the first n iterations. More specifically, we know the for each state Sk (0<k<n), the corresponding output ak+n. Refer to this link for the following matrix construction.

We can construct a matrix A=(S0,S1,...,Sn1) (the Ss are the rows of the matrix). The resultant vector is an,an+1,...,a2n1. Again, refer to the link for how to solve this problem - it is simple linear algebra mathematics. We should be able to recover the coefficients (taps). Refer to this page about Companion Matrix for more information on the "meaning" of the coefficients. TLDR, c0 corresponds to the coefficient of the lowest degree component, and cn1 corresponds to the coefficient of the highest degree component.

Sage implementation:

With the taps figured out, now we can use the Matrix form of Fibonacci LFSR. k=16×48, as before the given output, there is 16×48 bits produced in the init method.

The following Sage implementation uses the Berlekamp Massey algorithm, and should detail how to get the initial bit string (flag) with the given tap values.

One thing to note, and this burns A LOT of my time in solving, is that during testing, we cannot just pick any arbitrary value of taps and expect the above to work (even with the BM algorithm). The taps must be chosen such that the polynomial is minimal. The definition of a minimal polynomial is a polynomial of an algebraic number is the unique irreducible monic polynomial of smallest degree with 1 as the leading coefficient.

The method ONLY works on the given output, and I was too dumb to realize this.