e4ch

z3b.py

Jan 22nd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. from z3 import *
  2.  
  3. keystream = BitVec('keystream',258)
  4.  
  5. def next(x):
  6.   x = (x & 1) << 257 | x << 1 | x >> 255
  7.   y = 0
  8.   for i in range(256):
  9.     i0=(x>>i)&1
  10.     i1=((x>>i)&2)>>1
  11.     i2=((x>>i)&4)>>2
  12.     y|=(i0^(i1|i2))<<i
  13.   return y
  14.  
  15. keystreamnew=next(keystream)
  16.  
  17. oldres=0x52cc2cc124e3f2c28f5b9123904dc015babfd5c0988cb8d670f190fbb57593e2
  18. for l in range(128):
  19.   s=Solver()
  20.   s.add((keystream&0x30000000000000000000000000000000000000000000000000000000000000000)==0)
  21.   s.add(keystreamnew==oldres)
  22.   res=s.check()
  23.   resultnum=s.model()[keystream]
  24.   print(str("%.064x" % resultnum.as_long()))
  25.   oldres=resultnum.as_long()
  26.  
  27. print('Flag: '+oldres.to_bytes(32,'little').decode())
Advertisement
Add Comment
Please, Sign In to add comment