Created
August 8, 2023 14:29
-
-
Save taskie/71d01427183ab862dcd6d317cb1013c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
start_state = (1 << 11) | 1 | |
lfsr = start_state | |
period = 0 | |
for i in range(1023): | |
print(f"{i:04d} {lfsr:-012b} {lfsr:-03x}") | |
bit = (lfsr ^ (lfsr >> 1) ^ (lfsr >> 3) ^ (lfsr >> 8)) & 1 | |
lfsr = (lfsr >> 1) | (bit << 11) | |
if start_state == lfsr: | |
break | |
for i in range(1023): | |
j = (1023 - i) % 1023 | |
print(f"{j:04d} {lfsr:-012b} {lfsr:-03x}") | |
bit = (lfsr ^ (lfsr << 11) ^ (lfsr << 9) ^ (lfsr << 4)) & (1 << 11) | |
lfsr = (lfsr << 1) & 0b111111111111 | (bit >> 11) | |
if start_state == lfsr: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment