# decryption_complete: false # source: archive/local/external_voynich_units/voynich_decipherment_repro_bundle/decipherment_attack/plant_crib_attack.py # stated_sha256: 944a7028a8977f51cc5d36a1b746c3c450afaec5503e1a34f0d32e56cb41b026 # matches_stated_sha256: false # pdf_pages: 797-800 # 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 1796 archive/local/external_voynich_units/voynich_decipherme nt_repro_bundle/decipherment_attack/plant_crib_attack.p y SHA-256: 944a7028a8977f51cc5d36a1b746c3c450afaec5503e1a34f0d32e56cb41b026 | 11,294 bytes | workspace supplement #!/usr/bin/env python3 """Anchor-first Voynich decipherment attack. Use external iconographic claims already present in the ZL metadata ("same plant as ...") as semantic cribs. For each linked herbal page, identify the nearby pharmaceutical labels on the referenced page and rank them by whether the same surface family is unusually present in the full herbal-page text. This is not a generic statistics battery. Its output is a tentative bilingual codebook: Voynich label/family -> proposed plant identity, with explicit strength and counter-evidence. """ from __future__ import annotations import argparse import csv import json import math import re from collections import Counter, defaultdict from dataclasses import dataclass, field from pathlib import Path from statistics import median PAGE_RE = re.compile(r'^<([^>.]+)>\s+.]+)\.(\d+),([@+*=~&])([A-Za-z])[^>]*>\s*(.*)$') REF_RE = re.compile(r'Same\s+(?:plant|root|leaf)\s+as\s+(f\d+[rv](?:\d)?)\s*(?:\[\s*(\d+)\s*,\s*(\d+)\s*\])?', re.I) PLANT_RE = re.compile(r'Plant ID:\s*(.*)', re.I) BAD = set('?*<>{}[]()|@') SUBS = [ ('cth','T'), ('ckh','K'), ('cph','P'), ('cfh','F'), ('ch','C'), ('sh','S'), ('iin','N'), ('in','I'), ('ee','E') ] def strip_markup(s: str) -> str: s = re.sub(r'<[^>]*>', '', s) s = re.sub(r'\[([^:\]]*):[^\]]*\]', r'\1', s) s = re.sub(r'\{[^}]*\}', '', s) s = s.replace("'", '') return s def collapse(w: str) -> str: w = w.lower().strip() for a, b in SUBS: w = w.replace(a, b) return w def clean_tokens(s: str) -> list[str]: s = strip_markup(s) out = [] for w in re.split(r'[.,\s]+', s): w = w.strip().lower() if not w or any(c in BAD for c in w): continue if not re.fullmatch(r"[a-z]+", w): continue out.append(w) return out @dataclass class Label: raw: str collapsed: str locus: str line_no: int block: int @dataclass class Page: name: str comments: list[str] = field(default_factory=list) plant_id: str | None = None refs: list[tuple[str, int | None, int | None, str]] = field(default_factory=list) paragraph_tokens: list[str] = field(default_factory=list) labels: list[Label] = field(default_factory=list) def parse_zl(path: Path) -> dict[str, Page]: pages: dict[str, Page] = {} Voynich Complete Reproducibility Compendium - 2026-08-28 Page 1797 current: Page | None = None label_block = 0 previous_was_label = False for lineno, raw in enumerate(path.read_text(encoding='utf-8', errors='replace').splitlines(), 1): m = PAGE_RE.match(raw) if m: current = pages.setdefault(m.group(1), Page(m.group(1))) label_block = 0 previous_was_label = False continue if current is None: continue if raw.startswith('#'): comment = raw[1:].strip() current.comments.append(comment) pm = PLANT_RE.search(comment) if pm: current.plant_id = pm.group(1).strip() rm = REF_RE.search(comment) if rm: current.refs.append((rm.group(1), int(rm.group(2)) if rm.group(2) else None, int(rm.group(3)) if rm.group(3) else None, comment)) previous_was_label = False continue if not raw.strip(): previous_was_label = False continue lm = LOCUS_RE.match(raw) if not lm: previous_was_label = False continue page, num, marker, typ, text = lm.groups() toks = clean_tokens(text) if typ == 'P': current.paragraph_tokens.extend(toks) previous_was_label = False elif typ == 'L': if not previous_was_label: label_block += 1 for tok in toks: current.labels.append(Label(tok, collapse(tok), f'{page}.{num}', lineno, label_block)) previous_was_label = True else: previous_was_label = False return pages def lev(a: str, b: str) -> int: if len(a) < len(b): a, b = b, a prev = list(range(len(b) + 1)) for i, ca in enumerate(a, 1): cur = [i] for j, cb in enumerate(b, 1): cur.append(min(cur[-1] + 1, prev[j] + 1, prev[j-1] + (ca != cb))) prev = cur return prev[-1] def ndist(a: str, b: str) -> float: return lev(a, b) / max(len(a), len(b), 1) def candidate_labels(target: Page, row: int | None, col: int | None) -> tuple[list[Label], str]: """Use coordinates when they map cleanly; otherwise return the local block/all labels. ZL's [r,c] notation is iconographic and is not uniform across foldouts. We therefore never silently pretend an exact map: exact/block/all is recorded. """ if not target.labels: return [], 'none' blocks: dict[int, list[Label]] = defaultdict(list) for lab in target.labels: blocks[lab.block].append(lab) if row is not None and row in blocks: block = blocks[row] if col is not None and 1 <= col <= len(block): return [block[col-1]], 'exact-block-coordinate' return block, 'row-block' return target.labels, 'all-target-labels' def page_match(label: str, tokens: list[str]) -> tuple[float, str, int, int]: if not tokens: return 1.0, '', 0, 0 ctoks = [collapse(t) for t in tokens] ds = [(ndist(label, t), raw) for t, raw in zip(ctoks, tokens)] ds.sort() best_d, best_raw = ds[0] threshold = max(1, round(len(label) * 0.25)) family = sum(lev(label, t) <= threshold for t in ctoks) exact = sum(label == t for t in ctoks) return best_d, best_raw, family, exact def main() -> None: Voynich Complete Reproducibility Compendium - 2026-08-28 Page 1798 ap = argparse.ArgumentParser() ap.add_argument('zl', type=Path) ap.add_argument('--outdir', type=Path, required=True) args = ap.parse_args() args.outdir.mkdir(parents=True, exist_ok=True) pages = parse_zl(args.zl) herbal_pages = [p for p in pages.values() if p.paragraph_tokens] links = [] for source in pages.values(): for target_name, row, col, rawref in source.refs: target = pages.get(target_name) if target is None: continue cands, mapping = candidate_labels(target, row, col) for lab in cands: src_best, src_word, family, exact = page_match(lab.collapsed, source.paragraph_tokens) bg = [] for p in herbal_pages: d, _, _, _ = page_match(lab.collapsed, p.paragraph_tokens) bg.append((d, p.name)) bg.sort() rank = 1 + next(i for i, (d, name) in enumerate(bg) if name == source.name) med = median(d for d, _ in bg) # Semantic-crib score: close match, specificity to linked page, # family support, and coordinate confidence. coord_bonus = {'exact-block-coordinate': 1.0, 'row-block': 0.5, 'all-target-labels': 0.0}.get(mapping, 0.0) score = (1.0 - src_best) * 3.0 + math.log1p(family) + math.log1p(exact) + max(0.0, med-src_best) * 2.0 + coord_bonus - math.log1p(rank) * 0.35 links.append({ 'source_page': source.name, 'plant_id': source.plant_id or '', 'reference': rawref, 'target_page': target_name, 'row': row, 'col': col, 'mapping': mapping, 'label_locus': lab.locus, 'label_raw': lab.raw, 'label_collapsed': lab.collapsed, 'best_source_token': src_word, 'normalised_edit_distance': round(src_best, 4), 'family_hits_on_source': family, 'exact_hits_on_source': exact, 'source_rank_among_text_pages': rank, 'background_median_min_distance': round(med, 4), 'crib_score': round(score, 4), }) links.sort(key=lambda x: (-x['crib_score'], x['source_page'], x['label_raw'])) csv_path = args.outdir / 'plant_crib_candidates.csv' with csv_path.open('w', newline='', encoding='utf-8') as f: w = csv.DictWriter(f, fieldnames=list(links[0].keys()) if links else []) if links: w.writeheader(); w.writerows(links) # Group report by semantic link, retaining top 5 candidate labels. grouped: dict[tuple, list[dict]] = defaultdict(list) for r in links: key = (r['source_page'], r['target_page'], r['row'], r['col'], r['plant_id'], r['reference']) grouped[key].append(r) report = [] report.append('# Anchor-first plant crib attack\n') report.append('This is a first decipherment pass, not a corpus-statistics survey. It uses iconographic \u201Csame plant/root\u201D links as external semantic cribs and asks which Voynich labels can plausibly name the linked plant.\n') report.append('A candidate is stronger when its label form (or a one-edit family) appears on the linked full herbal page, is unusually specific to that page relative to the rest of the manuscript, and the iconographic coordinate maps cleanly to the label block. A high score is **not yet a translation**; it is a candidate dictionary entry to be tested on independent occurrences.\n') for key, rows in sorted(grouped.items()): source, target, row, col, plant_id, reference = key report.append(f'## {source} \u2192 {target}[{row},{col}]') if plant_id: report.append(f'Proposed plant identity in ZL metadata: **{plant_id}** ') report.append(f'Iconographic note: `{reference}`\n') report.append('| rank | candidate label | locus | map | nearest form on herbal page | edit distance | family hits | exact hits | page rank | score |') report.append('|---:|---|---|---|---|---:|---:|---:|---:|---:|') for i, r in enumerate(sorted(rows, key=lambda x: -x['crib_score'])[:5], 1): report.append(f"| {i} | `{r['label_raw']}` | `{r['label_locus']}` | {r['mapping']} | `{r[ 'best_source_token']}` | {r['normalised_edit_distance']:.3f} | {r['family_hits_on_source']} | {r[ 'exact_hits_on_source']} | {r['source_rank_among_text_pages']} | {r['crib_score']:.2f} |") report.append('') report.append('## Interpretation rule\n') report.append('Promote a candidate to a provisional codebook entry only if it survives an independent test: the same label family should recur in another depiction, a related plant-part label, or a paragraph independently associated with the same botanical entity. No candidate in this file is accepted solely because it resembles a guessed Latin plant name.\n') md_path = args.outdir / 'plant_crib_report.md' md_path.write_text('\n'.join(report), encoding='utf-8') (args.outdir / 'plant_crib_candidates.json').write_text(json.dumps(links, indent=2, ensure_ascii=False), encoding='utf-8') print(f'parsed {len(pages)} pages; {len(grouped)} iconographic links; {len(links)} label candidates') print(csv_path) Voynich Complete Reproducibility Compendium - 2026-08-28 Page 1799 print(md_path) if __name__ == '__main__': main()