from operator import xor def shifting(initialvector): shiftedreg = initialvector.copy()…
- User
from operator import xor
def shifting(initial_vector): shifted_reg = initial_vector.copy() shifted_reg.insert(0, 0) shifted_reg.pop() return shifted_reg
def xoring(poly, vec): feedback_bit = vec[poly[0]] for x in range(1, len(poly)): feedback_bit = xor(feedback_bit, vec[poly[x]]) x += 1 return feedback_bit
def getKey(initial_vector): shifted_reg = initial_vector.copy() shifted_reg.insert(0, 0) pop_bit = shifted_reg.pop() return pop_bit
def lfsr(initial_vector, poly, m): num_clk = (2 ** m) key = [] for i in range(0, num_clk): if i == 0: shifted_vector = shifting(initial_vector) feedback = xoring(poly, initial_vector) shifted_vector[0] = feedback k = getKey(initial_vector) key.insert(i, k) else: shifted_vector = shifting(shifted_vector) for x in poly: feedback = xoring(poly, shifted_vector) shifted_vector[i] = feedback x += 1 k = getKey(shifted_vector) key.insert(i, k) i += 1 return key
print(lfsr([1, 0, 0], [1, 2], 3)) what is wrong , the app do not work efficiencly
- Assistant
There are a few issues with your code:
-
The import statement for
xorfunction from theoperatormodule is incorrect. The correct import statement should befrom operator import xor. -
In the
lfsrfunction, you are trying to iterate over the list using , but then incrementing inside the loop (). This is unnecessary and causes incorrect indexing when accessing the feedback bit. Simply remove the line as it is not needed.
-