在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