streamgame2.py
from flag import flag assert flag.startswith("flag{") assert flag.endswith("}") assert len(flag)==27 def lfsr(R,mask): output = (R << 1) & 0xffffff i=(R&mask)&0xffffff lastbit=0 while i!=0: lastbit^=(i&1) i=i>>1 output^=lastbit return (output,lastbit) R=int(flag[5:-1],2) mask=0x100002 f=open("key","ab") for i in range(12): tmp=0 for j in range(8): (R,out)=lfsr(R,mask) tmp=(tmp << 1)^out f.write(chr(tmp)) f.close()
key
def lfsr(R,mask): output = (R << 1) & 0xffffff i=(R&mask)&0xffffff lastbit=0 while i!=0: lastbit^=(i&1) i=i>>1 output^=lastbit return (output,lastbit) with open("key","rb") as f: filek = f.read(12) res = bytes() for a in range(2**21): R=a mask=0x100002 for i in range(12): tmp=0 for j in range(8): (R,out)=lfsr(R,mask) tmp=(tmp << 1)^out res += tmp.to_bytes(length=1,byteorder='big',signed=False) print(a,res,filek) if res == filek: break else: res = bytes()