defcal(s,mask): lm=len(bin(mask))-2 R=int(s[-1:]+s[:-1],2) ss='' for j inrange(lm,0,-1): (_,tk)=lfsr(R,mask) ss=str(tk)+ss R=int(s[j-2]+str(tk)+bin(R)[2:].rjust(lm,'0')[1:-1],2) return ss
defsolve(): mask=0b1010011000100011100 lm=len(bin(mask))-2 withopen('key','rb') as f: stream=f.read(c_div(lm,8)) s=''.join([bin(256+ord(it))[3:] for it in stream]) flag='flag{'+cal(s[:lm],mask)+'}' return flag