#!/usr/bin/env python3 """Which byte string reproduces the served file's recorded out-sha256? The file's embedded provenance header records out-sha256 7fd82f32f44b20f509114c5e0a808c6fa1b1bb2c8969edd8d00dcddbee7f6297 over 112 stdout body lines. Two live runs on this machine give different hashes, so the candidate set below covers the obvious normalisations before any conclusion is drawn. """ import hashlib import itertools import re TARGET = "7fd82f32f44b20f509114c5e0a808c6fa1b1bb2c8969edd8d00dcddbee7f6297" SRC = "attack-roughpair-error-01.js" def h(b): return hashlib.sha256(b).hexdigest() src = open(SRC, encoding="utf-8").read().splitlines() live = open("attack-roughpair-01.out", encoding="utf-8").read().split("\n") # the embedded OUTPUT block: from the first "// SEC 0" comment line to the "// done in" line start = next(i for i, l in enumerate(src) if l.startswith("// SEC 0")) end = next(i for i, l in enumerate(src) if l.startswith("// done in")) emb = [l[3:] if l.startswith("// ") else l[2:] for l in src[start:end + 1]] cands = {} for name, lines in (("embedded", emb), ("live", live)): for sep, tail in (("\n", "\n"), ("\n", ""), ("\r\n", "\r\n"), ("\r\n", "")): body = sep.join(lines) if tail: body += tail cands[f"{name} sep={sep!r} tail={tail!r}"] = body # live stdout with the wall clock replaced by every single-decimal value in 0.0..30.0 m = re.search(r"done in [0-9.]+s", "\n".join(live)) if m: for v in [f"{i/10:.1f}" for i in range(0, 301)]: for sep in ("\n", "\r\n"): body = sep.join(live) body = body[:m.start()] + f"done in {v}s; assertion failures: 0" + body[m.end():] cands[f"live timing={v} sep={sep!r}"] = body hits = [(k, h(v.encode())) for k, v in cands.items() if h(v.encode()) == TARGET] print("candidates tried:", len(cands)) print("matches:", hits if hits else "NONE") print("live stdout sha256:", h("\n".join(live).encode())) print("embedded body sha256:", h(("\n".join(emb) + "\n").encode())) print("embedded lines:", len(emb), "live lines:", len(live))