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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| from z3 import *
res = [0, 14, 20, 0, 4, 13, 15, 21, 24, 31, 32, 41, 45, 53] m = [BitVec('%i' % i, 32) for i in range(36)]
m += [0, 0, 0, 0, 0, 0, 0] sol = Solver()
for i in range(6): for j in range(6): sol.add(m[6 * i + j] < 0x10) sol.add(m[6 * i + j] >= 0) sol.add(((m[6 * i + j] & 0xF) >> 3) + ((m[6 * i + j] & 0x7) >> 2) + ((m[6 * i + j] & 0x3) >> 1) + (m[6 * i + j] & 0x1) & 1 == 0) sol.add(((m[6 * i + j] & 0xF) >> 3) + ((m[6 * i + j] & 0x7) >> 2) + ((m[6 * i + j] & 0x3) >> 1) + (m[6 * i + j] & 0x1) <= 2) if j == 0: sol.add((m[6 * i + j] & 7) >> 2 == 0) if j == 5: sol.add((m[6 * i + j] & 1) == 0) if i == 0: sol.add((m[j] & 0xf) >> 3 == 0) if i == 5: sol.add((m[j + 30] & 3) >> 1 == 0)
for q in range(3): v2 = res[q] // 10 v5 = res[v2] % 10 sol.add( Or( (m[6 * v2 + v5] & 0xF) >> 3 == 0, (m[6 * v2 + v5] & 0x3) >> 1 == 0 ) ) sol.add( Or( (m[6 * v2 + v5] & 0x7) >> 2 == 0, (m[6 * v2 + v5] & 0x1) == 0 ) ) sol.add(((m[6 * v2 + v5] & 0xF) >> 3) + ((m[6 * v2 + v5] & 0x7) >> 2) + ((m[6 * v2 + v5] & 0x3) >> 1) + (m[6 * v2 + v5] & 0x1) == 2) sol.add( Or( (m[6 * v2 + v5] & 0xF) >> 3 == 0, (m[6 * v2 - 6 + v5] & 0xF) >> 3 != 0 ) ) sol.add( Or( (m[6 * v2 + v5] & 0x3) >> 1 == 0, (m[6 * v2 + 6 + v5] & 0x3) >> 1 != 0 ) ) sol.add( Or( (m[6 * v2 + v5] & 0x7) >> 2 == 0, (m[6 * v2 - 1 + v5] & 0x7) >> 2 != 0 ) ) sol.add( Or( (m[6 * v2 + v5] & 0x1) == 0, (m[6 * v2 + 1 + v5] & 0x1) != 0 ) ) for q in range(10): v3 = res[q + 4] // 10 v6 = res[q + 4] % 10 sol.add( Or( And((m[6 * v3 + v6] & 0xF) >> 3 != 0, (m[6 * v3 + v6] & 0x3) >> 1 != 0), And((m[6 * v3 + v6] & 0x7) >> 2 != 0, (m[6 * v3 + v6] & 0x1) != 0) ) ) sol.add( Or( (m[6 * v3 + v6] & 0xF) >> 3 == 0, (m[6 * v3 + v6] & 0x3) >> 1 == 0, (m[6 * v3 - 6 + v6] & 0x7) >> 2 != 0, (m[6 * v3 - 6 + v6] & 0x1) != 0, (m[6 * v3 + 6 + v6] & 0x7) >> 2 != 0, (m[6 * v3 + 6 + v6] & 0x1) != 0, ) ) sol.add( Or( (m[6 * v3 + v6] & 0x7) >> 2 == 0, (m[6 * v3 + v6] & 0x1) == 0, (m[6 * v3 + 1 + v6] & 0xF) >> 3 != 0, (m[6 * v3 + 1 + v6] & 0x3) >> 1 != 0, (m[6 * v3 - 1 + v6] & 0xF) >> 3 != 0, (m[6 * v3 - 1 + v6] & 0x3) >> 1 != 0, ) )
sol.add((m[0] & 0x3) >> 1 == 1)
for i in range(6): for j in range(6): sol.add((m[6 * i + j] & 0x1) == (m[6 * i + (j + 1)] & 0x7) >> 2) sol.add((m[6 * i + j] & 0x3) >> 1 == (m[6 * (i + 1) + j] & 0xf) >> 3) sol.add((m[6 * i + j] & 0x7) >> 2 == (m[6 * i + (j - 1)] & 1)) sol.add((m[6 * i + j] & 0xf) >> 3 == (m[6 * (i - 1) + j] & 0x3) >> 1)
while sol.check() == sat: s = sol.model() print([s[i].as_long() for i in m[:36]]) sol.add(Or([m[i] != s[m[i]] for i in range(36)]))
flag = '' data = [3, 5, 5, 5, 5, 6, 10, 0, 3, 5, 6, 10, 9, 5, 12, 0, 10, 10, 3, 5, 5, 6, 10, 10, 9, 5, 6, 9, 12, 10, 0, 0, 9, 5, 5, 12] map = [0] * 36 map[0] = 2 map[6] = 8 x = 1 y = 0 while ( map[0] != 3 ): for i in range(1, 5): if i == 1 and x - 1 >= 0: if map[x * 6 + y] + 8 == data[x * 6 + y]: map[x * 6 + y] |= 8 map[(x - 1) * 6 + y] |= 2 x -= 1 flag += str(i) break if i == 2 and x + 1 <= 5: if map[x * 6 + y] + 2 == data[x * 6 + y]: map[x * 6 + y] |= 2 map[(x + 1) * 6 + y] |= 8 x += 1 flag += str(i) break if i == 3 and y - 1 >= 0: if map[x * 6 + y] + 4 == data[x * 6 + y]: map[x * 6 + y] |= 4 map[x * 6 + y - 1] |= 1 y -= 1 flag += str(i) break if i == 4 and y + 1 <= 5: if map[x * 6 + y] + 1 == data[x * 6 + y]: map[x * 6 + y] |= 1 map[x * 6 + y + 1] |= 4 y += 1 flag += str(i) break print("d3ctf{" + flag + "}")
|