Write a new program using your LFSR function from the first problem. Start from state 0x00000001, then run a loop counting all the possible states in the LFSR before it cycles back to 0x00000001. This is shown by the following pseudocode: count = 0; initial = state = 0x00000001; do { state = LFSR(state); count++; while (state != initial); print count;
Write a new
count = 0;
initial = state = 0x00000001;
do {
state = LFSR(state);
count++;
while (state != initial);
print count;
Verify that the number of states is (2^15) - 1 = 32767 . Your program should complete within 30 seconds. If it takes longer then you likely have entered an infinite loop.
Answer:
Here's a Python program that uses the LFSR function from the first problem and counts the number of possible states before the LFSR cycles back to 0x00000001:
def LFSR(state):
mask = 0x80000001
feedback = ((state & 1) ^ ((state >> 15) & 1)) << 31
state = (state >> 1) & 0x7FFFFFFF
state = state | feedback
state = state & mask
return state
count = 0
initial = state = 0x00000001
while state != initial or count == 0:
state = LFSR(state)
count += 1
print(count)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps