1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| from z3 import * def get_models(s): while s.check() == sat: m = s.model() yield m s.add(Or([sym() != m[sym] for sym in m.decls()]))
def first_enc(input,input2): inpt=input[:] for i in range(len(inpt)): inpt[i]=input[i]^input2[i] return inpt arr0 = [249,91,149,113,16,91,53,41] arr1 = [43,1,6,69,20,62,6,44,24,113,6,35,0,3,6,44,20,22,127,60] arr2 = [ 90, 100, 87, 109, 86, 108, 86, 105, 90, 104, 88, 102] arr = [BitVec('arr[%d]'%i, 32) for i in range(39)] s = Solver() s.add(arr[0]==ord('f')) s.add(arr[1]==ord('l')) s.add(arr[2]==ord('a')) s.add(arr[3]==ord('g')) s.add(arr[4]==ord('{')) s.add(arr[5]==ord('5')) s.add(arr[38]==ord('}')) for i in range(len(arr)): s.add(arr[i]<128) s.add(arr[i]>32) a = arr[6:30:3]
for i in range(len(a)): s.add((a[i]*17684+372511)%257==arr0[i]) b = arr[-2:33:-1]*5 c = first_enc(b,arr[7:27])
for i in range(len(c)): s.add(c[i]==arr1[i]) p = 0 for i in range(28,34): s.add((arr[i]+107)/16+77 ==arr2[p]) s.add((arr[i]+117)%16+99==arr2[p+1]) p+=2 print s.check() for m in get_models(s): serial = [m[arr[i]].as_long() for i in range(39)] key = '' for _ in serial: key += chr(_) print key
|