

This code is an emulator, meaning that it does not operate on actual bits, but on a Python list of 0s and 1s symbolizing the bits. That means, that there should be an even number of taps, and they should all be relatively prime, i.e. for it to have the longest period (the number of steps before it returns to inital state), the polynomial should be primitive. In order to maximize the length of the LFSR, i.e. It has to satisfy several properties - it is expressed as a polynomial modulo 2, meaning all the coefficients must be either 1 or 0.Įxample: a register with taps at positions 11, 10, 7, 3 will have a feedback polynomial: The location and number of the taps is determined by the register's reciprocal characteristic polynomial. Other linear functions can be used as well. This constitutes one step of the feedback shift register. It operates by taking the bits of the inital value (called fill or seed), shifting them one position to the left and replacing the leaving bit with exclusive-or of the leaving bit and bits at special locations in the register called the taps. Shifting the Galois output ten times to the right, we would find the same output of the Fibonacci LFSR.A simple emulator of a linear-feedback shift register (LFSR). Just for fun, let's try it with a mirroring output. In order to obtain this kind of coupled outputs, the taps of the Galois register must be the counterparts of the ones of the Fibonacci register. The seed choice is not relevant since it would introduce only a shift in the output. In such a register, all possible states are visited - except the null state, which would make the register collapse in a sequence of 0s. The two types of LFSR produce the same result - minus a reflection and a translation - when the taps are the ones generating a maximally long LFSR.
