Generation

generate functionSun, 23 Apr 2023

generate LFSR using a seed and primitive polynomial

import numpy as np def lfsr(seed, p): # initialize the lfsr lfsr = seed # initialize the output string out = np.zeros(len(seed)-1) for i in range(len(seed)-1): # sum the tap bits tap = np.sum([lfsr[i] for i in range(len(lfsr)) if p[i] == '1']) # exclusive or the tap bits tap ^= lfsr[-1] # shift the lfsr lfsr = np.insert(lfsr[0:-1], 0, tap) # record the output bit out[i] = lfsr[-1] return out

Want to kickstart your project?Use the new AI Studio to create your code