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 152 153 154 155 156
| """CodeShell.kr — infinity-parallax: solve with data-located rotations.
Decisive finding (parallax_oddbits.py): the red channel of every plate is an otherwise-all-EVEN gradient, and the data bits are written as ODD red values. Each plate has exactly ONE rotation that puts those odd pixels inside the 16x16 patch at (8,8), and with symbol mapping = rank of {64,112,160,208} and packing = 3 two-bit symbols per byte, those odd pixels are exactly a subset of the 16 shuffle-selected patch positions. (per_byte=4 and the (v>>4)&3 mapping both fail that test.)
So each plate's rotation is determined by its own content -- no need to guess it from edge matching. Edge matching only has to place the plates in the 8x8 grid.
Run: uv run python solvers/parallax2.py """
import hashlib import random from pathlib import Path
import numpy as np from PIL import Image
ROOT = Path('codeshell') PL = ROOT / 'extracted' / 'infinity-parallax' / 'plates' ZERO = (0,) * 36
def edges_raw(a): g = a[:, :, 0] return (g[0, 6:42], g[6:42, 47], g[47, 6:42], g[6:42, 0])
def pack3(sym): """36 two-bit symbols -> 12 bytes, 3 symbols per byte, low first.""" out = bytearray() for i in range(0, len(sym), 3): v = 0 for j, s in enumerate(sym[i:i + 3]): v |= s << (2 * j) out.append(v) return bytes(out)
def main(): plates = {f.stem: np.asarray(Image.open(f).convert('RGB')).astype(int) for f in sorted(PL.glob('*.png'))} vals = [] for a in plates.values(): vals.extend(int(v) for e in edges_raw(a) for v in e) srt = sorted(set(vals)) smap = {v: i for i, v in enumerate(srt)} print(f"alphabet {srt} -> {sorted(smap.values())}")
rot, sigs = {}, {} for name, a in plates.items(): cands = [k for k in range(4) if int((np.rot90(a, -k)[8:24, 8:24, 0] & 1).sum()) > 0] if len(cands) != 1: print(f" !! {name}: {len(cands)} candidate rotations {cands}") k = cands[0] rot[name] = k b = np.rot90(a, -k) e = edges_raw(b) sigs[name] = tuple(tuple(smap[int(v)] for v in e[s]) for s in range(4)) from collections import Counter print("rotation histogram:", dict(Counter(rot.values())))
cnt = Counter() for name, s in sigs.items(): for side in range(4): cnt[s[side]] += 1 bad = {k: v for k, v in cnt.items() if k != ZERO and v != 2} print(f"non-zero signatures with count != 2: {len(bad)}") print(f"zero-signature edges: {cnt[ZERO]}")
names = sorted(plates) grid, used = {}, set()
def fits(i, j, name): N, E, S, W = sigs[name] if (i, j - 1) in grid: if sigs[grid[(i, j - 1)]][1] != W: return False elif W != ZERO: return False if (i - 1, j) in grid: if sigs[grid[(i - 1, j)]][2] != N: return False elif N != ZERO: return False if i == 7 and S != ZERO: return False if j == 7 and E != ZERO: return False return True
def dfs(pos): if pos == 64: return True i, j = divmod(pos, 8) for name in names: if name in used or not fits(i, j, name): continue grid[(i, j)] = name used.add(name) if dfs(pos + 1): return True del grid[(i, j)] used.discard(name) return False
if not dfs(0): print("assembly failed with fixed rotations") return print("assembled 8x8 with fixed rotations")
for gdelta in range(4): st = bytearray() for i in range(8): for j in range(8): name = grid[(i, j)] k = (rot[name] + gdelta) % 4 b = np.rot90(plates[name], -k) e = edges_raw(b) blob = b''.join(pack3(tuple(smap[int(v)] for v in e[s])) for s in range(4)) rng = random.Random(hashlib.sha256(blob).digest()) idx = list(range(256)) rng.shuffle(idx) bits = 0 for t in idx[:16]: r, c = 8 + t // 16, 8 + t % 16 bits = (bits << 1) | (int(b[r, c, 0]) & 1) mask = hashlib.sha256(blob + b'ink').digest()[:2] st += bytes(x ^ y for x, y in zip(bits.to_bytes(2, 'big'), mask)) print(f" gdelta={gdelta}: {bytes(st[:12])!r}") if bytes(st).startswith(b'INFINITY'): payload, chk = bytes(st[8:40]), bytes(st[40:72]) h = hashlib.sha256(payload).hexdigest() print(f"\n *** INFINITY found at gdelta={gdelta}") print(f" payload: {payload.hex()}") print(f" sha256 : {h}") print(f" check : {chk == hashlib.sha256(payload).digest()}") print(f"\n ANSWER : CodeShell{{{h}}}")
if __name__ == '__main__': main()
|