Question
Need help with a Cryptology / Cryptography problem using Python: (LFSR) a) Run a 4-register LFSR with the following specifications for 10 steps: (p3, p2,
Need help with a Cryptology / Cryptography problem using Python:
(LFSR)
a) Run a 4-register LFSR with the following specifications for 10 steps: (p3, p2, p1, p0) = (0,1,1,1), in other words, s4 = s0 + s1+ s2 (mod 2), and initial seed (s0,s1, s2, s3) = (1,0,0,0). (You can do this by hand, or you can modify my implementation, or implement an LFSR yourself.)
b) What's the period of your LFSR? Is it maximal?
Professor's implementation (lfsr.py):
from random import *
reg = {}
#Registers s_{n-1} ... s_0 are stored in list reg: # # reg[n-1] reg[n-2] ... reg[0] # s_{n-1} s_{n-2} s_0 # #when displaying reg, we need to reverse order, so reg[0] is rightmost #seed is written in order s_0 s_1 s_2...s_{n-1}
def seed_reg(): global reg reg = seed[:] #create copy of seed
#implements s_{n+3} = s_{n+2} + s_{n} def s(): global reg new_bit = (reg[2] + reg[0]) % 2 out_bit = reg[0] reg = reg[1:] reg.append(new_bit) return out_bit
#implements s_{n+5} = s_{n+4} + s_{n+3} + s_{n+1} + s_{n} def s(): global reg new_bit = (reg[4]+reg[3]+reg[1] + reg[0]) % 2 out_bit = reg[0] reg = reg[1:] reg.append(new_bit) return out_bit
def cur_reg(): 'display current state of register reg' return ''.join(map(str, reg[::-1])) #or use loop; displaying reg
f = s #or some other linear feedback shift register seed = [1,0,0,0,0] #for s0s1...
seed_reg()
for i in range(40): print('Index: {} Register: {} Output: {}'.format(i,cur_reg(),f()))
from random import reg #Registers s in-1) s 0 are stored in list reg reg In-1] reg 21 regloj In-2 s in-1 s in-2 s 0 #when displaying reg, we need to reverse order, so reg[0] is rightmost seed is written in order a 0 a 1 a 2 s in-1 def seed reg global reg reg seed j #create copy of seed. iimplements s in 31 s in 2 {n def s global reg new bit (reg 12 reg [0]) 2 out bit reg [0] reg reg [1: reg append (new bit) return out bit iimplements is in 5 def s global reg new bit (reg [4] reg [3] +reg [1] reg [01) 2 out bit reg [0] reg reg [1 reg. append (new bit) return out bit def cur reg display current state of register reg return join (map (str reg C: 11) tor use loop displaying reg f s ior some other linear feedback shift register seed. [1,0, 0, 0, 0] tfor 30 a1... seed reg for i in range (40) print ('Index Register Output format (i, cur reg f from random import reg #Registers s in-1) s 0 are stored in list reg reg In-1] reg 21 regloj In-2 s in-1 s in-2 s 0 #when displaying reg, we need to reverse order, so reg[0] is rightmost seed is written in order a 0 a 1 a 2 s in-1 def seed reg global reg reg seed j #create copy of seed. iimplements s in 31 s in 2 {n def s global reg new bit (reg 12 reg [0]) 2 out bit reg [0] reg reg [1: reg append (new bit) return out bit iimplements is in 5 def s global reg new bit (reg [4] reg [3] +reg [1] reg [01) 2 out bit reg [0] reg reg [1 reg. append (new bit) return out bit def cur reg display current state of register reg return join (map (str reg C: 11) tor use loop displaying reg f s ior some other linear feedback shift register seed. [1,0, 0, 0, 0] tfor 30 a1... seed reg for i in range (40) print ('Index Register Output format (i, cur reg fStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started