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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| from z3 import * import hashlib
def check_and_out(arr): assert len(arr) == 4 s = "" for row in arr: for col in row: if col == 0: s += "0" elif col == 1: s += "1" elif col == -1: s += "2" md5_hash = hashlib.md5(s.encode()).hexdigest() if md5_hash == "aac82b7ad77ab00dcef90ac079c9490d": print("[+] success", s) return True else: return False
def col_to_int(col): return Sum([If(arr[r][col] == -1, 2, arr[r][col]) * (10 ** (rows - 1 - r)) for r in range(rows)])
solver = Solver()
rows, cols = 0x4, 0x27 arr = [[Int(f"arr_{r}_{c}") for c in range(cols)] for r in range(rows)]
for c in range(cols - 1): solver.add(col_to_int(c) < col_to_int(c + 1)) first_row = [0] * 13 + [1] * 13 + [-1] * 13 for c in range(cols): solver.add(arr[0][c] == first_row[c])
for r in range(rows): for c in range(cols): solver.add(Or(arr[r][c] == -1, arr[r][c] == 0, arr[r][c] == 1))
for r in range(rows): solver.add(Sum([If(arr[r][c] == -1, 1, 0) for c in range(cols)]) == cols // 3) solver.add(Sum([If(arr[r][c] == 0, 1, 0) for c in range(cols)]) == cols // 3) solver.add(Sum([If(arr[r][c] == 1, 1, 0) for c in range(cols)]) == cols // 3)
for c in range(cols): solver.add(Sum([If(arr[r][c] == 1, 1, 0) for r in range(rows)]) != 4)
for c1 in range(cols): for c2 in range(c1 + 1, cols): constraints = [Not(arr[r][c1] == -arr[r][c2]) for r in range(rows)] solver.add(Or(*constraints))
all_vars = [var for sublist in arr for var in sublist]
may_result_num = 0 while True: if may_result_num % 100 == 0: print("[+] number:", may_result_num) if solver.check() == sat: model = solver.model() example_arr = [[model.evaluate(arr[r][c]).as_long() for c in range(cols)] for r in range(rows)] res = check_and_out(example_arr) may_result_num += 1 if res: break else: block = [] for v in all_vars: c = model[v] block.append(v != c) solver.add(Or(block)) else: print("[*] No solution found.") break
|