在Sage中工作基本上是python,我相信。我给了下面的代码。Python:一个变量被赋值并且没有改变另一个变化
def lfsr_1(regs,tabs):
I=regs
leng=len(I)
count=0
while True:
FB=0
print "Before"
print I
print regs
print temp
for i in range(0,leng):
FB=FB+tabs[i]*I[i] //Calculating the feedback value
for i in range(0,leng):
regs[leng-(i+1)]=regs[leng-(i+1)-1] //Shifting regs one bit to the right
I[0]=FB //Adding the feedback at the end
count=count+1 //Incrementing count value which will contain the periodicity
print "After"
print I
print regs
print temp
if (I==regs): //End when the initial state is repeated again. Now, count will contain the periodicity
break
输入变量的初始化如下
tabs=[GF(2)(1),0,0,1,1,1]
regs=[GF(2)(0),1,1,0,1,1]
temp=regs
然而,即时得到的输出为:
Before
[0, 0, 1, 1, 0, 1]
[0, 0, 1, 1, 0, 1]
[0, 0, 1, 1, 0, 1]
After
[0, 0, 0, 1, 1, 0]
[0, 0, 0, 1, 1, 0]
[0, 0, 0, 1, 1, 0]
不知道这是如何发生的“我”的变化连同“暂存器。 '我'在代码中永远不会改变。我的任务有什么问题吗?
附录:尝试实现线性反馈移位寄存器。代码是计算LFSR的周期性。 regs是初始状态,我用于检查regs何时再次返回到初始状态(计算周期性),temp只是一个测试变量,以查看是否另一个初始化变量也将被移位。
如果你想提供一些关于你的最终目标是什么的信息,并且评论你的代码,它会使你更容易帮助你。 – pzkpfw