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
|
from z3 import * 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]
flag = [BitVec('flag{}'.format(i), 32) for i in range(39)] s = Solver() s.add(flag[38] == 125) s.add(flag[0] == ord('f')) s.add(flag[1] == ord('l')) s.add(flag[2] == ord('a')) s.add(flag[3] == ord('g')) s.add(flag[4] == ord('{')) s.add(flag[5] == 53) count = 0 for i in range(6, 30, 3): s.add((flag[i]*17684+372511)%257 == arr0[count]) s.add(flag[i]<128) s.add(flag[i]>0) count += 1 print(s) count = 0 for i in range(7, 27, 4): s.add((flag[i]^flag[37]) == arr1[count]) s.add((flag[i+1]^flag[36]) == arr1[count+1]) s.add((flag[i+2]^flag[35]) == arr1[count+2]) s.add((flag[i+3]^flag[34]) == arr1[count+3]) count += 4
count = 0 for i in range(28, 34): s.add((flag[i]+107) / 16 +77 == arr2[count]) s.add((flag[i]+117) % 16 +99 == arr2[count+1]) count += 2
s.check() m = s.model() print(m) result = "" for f in flag: print(f) result += chr(m[f].as_long()) print(result)
|