Voynich Complete Reproducibility Compendium - 2026-08-28 Page 2642 archive/local/external_voynich_units/voynich_decipherme nt_repro_bundle/decipherment_attack_v5/unit_probe.py SHA-256: df29b7935eb417c27b959790e2dbb7fe4270b5d56e906b3be1898708b5fede29 | 13,165 bytes | workspace supplement #!/usr/bin/env python3 """E1: BPE unit-discovery probe of the verbose-cipher hypothesis. E2: homophone-family collapse probe of the codebook hypothesis. Corpora are matched in glyph count. All entropies are plug-in, bigrams cross word boundaries within lines, spaces are not symbols (paper's convention). """ from __future__ import annotations import json, math, random, re, sys from collections import Counter, defaultdict from pathlib import Path SCRATCH = Path(__file__).resolve().parent BUNDLE = Path(__file__).resolve().parent.parent sys.path.insert(0, str(BUNDLE / "decipherment_attack")) from plant_crib_attack import LOCUS_RE, PAGE_RE, clean_tokens, collapse, lev # type: ignore rng = random.Random(20260808) # ------------------------------------------------------------- load corpora def voynich_lines() -> list[list[str]]: """Paragraph-locus lines of raw EVA tokens (no collapse).""" lines = [] for raw in (BUNDLE / "voynich_calibration_sources" / "ZL3b.txt").read_text( encoding="utf-8", errors="replace").splitlines(): lm = LOCUS_RE.match(raw) if not lm: continue page, num, marker, typ, txt = lm.groups() if typ != "P": continue toks = clean_tokens(txt) if toks: lines.append(toks) return lines def latin_words() -> list[str]: txt = "" for f in ("caesar_la.txt", "caesar_la2.txt"): t = (SCRATCH / "latin_controls" / f).read_text(encoding="utf-8", errors="replace") # strip gutenberg header/footer a = t.find("*** START") b = t.find("*** END") t = t[t.find("\n", a)+1:b if b > 0 else len(t)] txt += " " + t txt = txt.lower() txt = txt.replace("v", "u").replace("j", "i") words = re.findall(r"[a-z]+", txt) return [w for w in words if len(w) >= 1] def to_lines(words: list[str], per_line: int = 9) -> list[list[str]]: return [words[i:i+per_line] for i in range(0, len(words), per_line)] # ----------------------------------------------------------------- ciphers CIPHER_ALPHABET = "abcdefghijklmnopqrst" # 20 output glyphs def make_groups(letters: list[str], lengths: dict[str, int]) -> dict[str, str]: used, out = set(), {} for ch in letters: L = lengths[ch] while True: g = "".join(rng.choice(CIPHER_ALPHABET) for _ in range(L)) if g not in used: used.add(g); out[ch] = g; break return out def cipher_corpus(lines: list[list[str]], table) -> list[list[str]]: out = [] for ln in lines: out.append(["".join(table(c) for c in w) for w in ln]) return out def build_ciphers(lat_lines): freq = Counter(c for ln in lat_lines for w in ln for c in w) letters = [c for c, _ in freq.most_common()] # verbose-2: every letter -> unique 2-glyph group v2 = make_groups(letters, {c: 2 for c in letters}) # verbose-1-3: frequency-ranked group lengths (common letters short) lens = {c: (1 if i < 7 else 2 if i < 16 else 3) for i, c in enumerate(letters)} v13 = make_groups(letters, lens)