# decryption_complete: false # source: archive/local/external_voynich_units/voynich_decipherment_repro_bundle/decipherment_attack_v6/attack_voynich.py # stated_sha256: 3e6fac36a5c4e27fc6403d82cde309e178ff3a0a90f99d85eadc188aa81fa159 # matches_stated_sha256: false # pdf_pages: 651-652 # note: The stated SHA-256 is the digest printed in the PDF. # The PDF page extract follows the form feed. decryption_complete stays false. Voynich Complete Reproducibility Compendium - 2026-08-28 Page 2650 archive/local/external_voynich_units/voynich_decipherme nt_repro_bundle/decipherment_attack_v6/attack_voynich. py SHA-256: 3e6fac36a5c4e27fc6403d82cde309e178ff3a0a90f99d85eadc188aa81fa159 | 4,220 bytes | workspace supplement #!/usr/bin/env python3 """The substitution attack applied to Voynichese, per Currier dialect, with an n-gram-generator negative control. For each (stream, m, language): hill-climb classes->letters on even lines, evaluate held-out per-symbol log-likelihood on odd lines, normalise into the language-match index (0 = no sequential structure recovered beyond frequency matching, 1 = as language-like as real held-out text of that language). The negative control is a corpus sampled from an order-3 glyph model fitted to each stream (same size, same token/line structure) and pushed through the IDENTICAL pipeline: it bounds how much "language-likeness" the optimizer can manufacture from small-scale glyph statistics alone. """ from __future__ import annotations import json, random, sys from collections import Counter, defaultdict from pathlib import Path HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) from attack_lib import (build_lms, pipeline_classes, match_index, voynich_lines_by_language, truncate) OUT = HERE / "output" OUT.mkdir(exist_ok=True) LANGS = ["latin", "latin_novowels", "italian", "german", "french", "english", "hebrew"] M_MAIN = 23 M_SENS = [20, 26] K = 64 def ngram_generate(lines, seed=7): """Order-3 char model (incl. token boundary '#') fitted to the stream; sample a same-shape corpus. Generation is seeded from real contexts that end at a token boundary; there is NO fallback to the original lines (a silent fallback would make the negative control identical to the data).""" rng = random.Random(seed) big = "#" + "#".join(w for ln in lines for w in ln) + "#" ctx = defaultdict(Counter) for i in range(2, len(big)): ctx[big[i - 2:i]][big[i]] += 1 starts = [big[i:i + 2] for i in range(1, len(big) - 2) if big[i + 1] == "#"] out = [] for ln in lines: target_tokens = len(ln) s = rng.choice(starts) tokens, cur = [], "" guard = 0 while len(tokens) < target_tokens and guard < 20000: guard += 1 dist = ctx.get(s[-2:]) if not dist: s += rng.choice(starts) cur = "" continue chars, weights = zip(*dist.items()) c = rng.choices(chars, weights=weights)[0] s += c if c == "#": if cur: tokens.append(cur) cur = "" else: cur += c out.append(tokens if tokens else ["qokedy"]) return out def run_stream(name, lines, lms, m_list, langs, results, restarts=8): print(f"=== {name}: {len(lines)} lines, " f"{sum(len(w) for ln in lines for w in ln)} glyphs", flush=True) segmap, ustream, maps = pipeline_classes(lines, K, m_list) for m in m_list: cm = maps[m] for lang in langs if m == M_MAIN else ["latin", "hebrew"]: lm, anchor = lms[lang] r = match_index(ustream, cm, m, lm, anchor, restarts=restarts) key = f"{name}|m{m}|{lang}" results[key] = dict(index=r["index"], test_bits=r["test_bits"], scrambled_bits=r["scrambled_bits"], Voynich Complete Reproducibility Compendium - 2026-08-28 Page 2651 anchor_bits=r["anchor_bits"]) print(f"{name:12s} m={m:2d} {lang:14s} index={r['index']:.3f} " f"bits={r['test_bits']:.3f} scr={r['scrambled_bits']:.3f} " f"anchor={anchor:.3f}", flush=True) if __name__ == "__main__": lms = build_lms(LANGS) by_lang = voynich_lines_by_language() A_lines = by_lang.get("A", []) B_lines = by_lang.get("B", []) results = {} run_stream("voynich_A", A_lines, lms, [M_MAIN] + M_SENS, LANGS, results) run_stream("voynich_B", B_lines, lms, [M_MAIN] + M_SENS, LANGS, results) run_stream("ngram_ctl_B", ngram_generate(B_lines), lms, [M_MAIN], LANGS, results) run_stream("ngram_ctl_A", ngram_generate(A_lines), lms, [M_MAIN], LANGS, results) (OUT / "attack_results.json").write_text(json.dumps(results, indent=2, default=float)) print("done")