75 lines
1.6 KiB
Python
75 lines
1.6 KiB
Python
# r_podwojne = b"01001001001001000011101101101111011110"
|
|
|
|
N = 8
|
|
# r od n
|
|
r1 = b"11111111"
|
|
r2 = b"11111111"
|
|
r1 = (int(r1, 2)) + (1 << N)
|
|
r2 = (int(r2, 2)) + (1 << N)
|
|
# t od 1
|
|
t1 = b"10001110"
|
|
t2 = b"10010101"
|
|
t1 = (int(t1, 2)) + (1 << N)
|
|
t2 = (int(t2, 2)) + (1 << N)
|
|
#
|
|
pdpkt_a = b"000011"
|
|
pdkpt_b = b"101001"
|
|
pdpkt_a = (int(pdpkt_a, 2)) + (1 << N)
|
|
pdkpt_b = (int(pdkpt_b, 2)) + (1 << N)
|
|
|
|
def nastepny_bit(r, t):
|
|
rc = r
|
|
tc = t
|
|
wyn = None
|
|
#print(bin(rc))
|
|
#print(bin(tc))
|
|
for i in range(N):
|
|
bit = rc & 1
|
|
bit_z_t = tc & 1
|
|
if bit_z_t == 1:
|
|
if wyn == None:
|
|
wyn = bit
|
|
else:
|
|
wyn = wyn ^ bit
|
|
rc = rc >> 1
|
|
tc = tc >> 1
|
|
#print(bit)
|
|
#print(wyn)
|
|
#print(bin(rc))
|
|
#print(bin(tc))
|
|
#print("xor", bin(wyn))
|
|
wywalane_z_r = r & 1
|
|
#print("r", bin(r))
|
|
r = r >> 1
|
|
#print("podzielone", bin(r))
|
|
r = r - (1 << N - 1)
|
|
r = r + (wyn << N - 1)
|
|
r = r + (1 << N)
|
|
#print("r dodane", bin(r))
|
|
return r, wywalane_z_r
|
|
|
|
|
|
#r1, b = nastepny_bit(r1, t1)
|
|
#print(bin(r1))
|
|
#print(b)
|
|
|
|
|
|
def shrinking_generator(r1, r2, t1, t2,rundy=10000):
|
|
wyn = []
|
|
for i in range(rundy):
|
|
r1, l1 = nastepny_bit(r1, t1)
|
|
r2, l2 = nastepny_bit(r2, t2)
|
|
if l1 == 1:
|
|
wyn.append(l2)
|
|
print(l2, end="")
|
|
if i>0 and i%500==0:
|
|
print()
|
|
print()
|
|
return wyn
|
|
|
|
wyn = shrinking_generator(r1,r2,t1,t2)
|
|
print(len(wyn))
|
|
|
|
wyn = shrinking_generator(pdpkt_a,pdkpt_b,pdpkt_a,pdkpt_b)
|
|
print(len(wyn))
|
|
print(wyn) |