# -*- coding: utf-8 -*- """五段加法二宿主复验 · Windows/IDBots · 真实(Twin) · 最终版 Wuhao 件: pin://dd342aa4e7110d22cddf964a8671fea39e7fc0e3370bdad05b8a51e0184d6c6ai0 模型: R = 35 + 骨架 + Σ条目 + max(k-1, 0) 骨架 = 顶层 JSON 置空 truncation_points 后的序列化长度 条目 = truncation_points[] 每枚单独序列化后逐个相加 序列化: json.dumps(ensure_ascii=False, separators=(",", ":")) 字符口径: python len() = Unicode code point(Git Bash wc -m 按字节计,禁用) """ import json, io, os SPILL = r"C:\Users\vinso\AppData\Roaming\IDBots\dsh-sessions\v0\spill" PREFIX = "- RECEIPT read_metaweb_pins_batch: " NUM_KEYS = ["requested", "readable_upstream", "returned", "omitted", "unreadable", "truncation_point_count", "bytes_written"] def ser(obj): return json.dumps(obj, ensure_ascii=False, separators=(",", ":")) rows = [] for root, dirs, files in os.walk(SPILL): for fn in files: p = os.path.join(root, fn) try: txt = io.open(p, encoding="utf-8", errors="strict").read() except Exception: continue for line in txt.splitlines(): if not line.startswith(PREFIX): continue try: d = json.loads(line[len(PREFIX):]) except Exception: continue if isinstance(d, dict) and "truncation_points" in d: rows.append((p, line, d)) print("n =", len(rows)) resid_zero = 0 print("\n[1] 五段加法残差(R 实测 vs 35+骨架+Σ条目+max(k-1,0))") table = [] for p, line, d in rows: R = len(line) k = len(d["truncation_points"]) top = dict(d); top["truncation_points"] = [] sk = len(ser(top)) ent = sum(len(ser(e)) for e in d["truncation_points"]) pred = 35 + sk + ent + max(k - 1, 0) resid = R - pred if resid == 0: resid_zero += 1 table.append((os.path.basename(p)[:26], R, k, sk, ent, pred, resid)) print(f" {os.path.basename(p)[:26]} | R={R} k={k:2} 骨架={sk} Σ条目={ent:4} 预测={pred} 残差={resid:+d}") print(f" 残差零: {resid_zero}/{len(rows)}") print("\n[2] 骨架结构常数(本席 12 键变体: 结构 = 212/213 + caliber(64) + Σ7数字位宽 + id项)") for p, line, d in rows: top = dict(d); top["truncation_points"] = [] sk = len(ser(top)) calib_len = len(d["caliber"]) widths = sum(len(str(d[kk])) - 1 for kk in NUM_KEYS) id_len = len(ser(d["omitted_ids"])) + len(ser(d["unreadable_ids"])) - 4 base = 212 if d["truncated"] else 213 recon = base + calib_len + widths + id_len print(f" {os.path.basename(p)[:26]} | 骨架 {sk} = {base}+{calib_len}+{widths}+{id_len} = {recon} {'OK' if recon==sk else 'FAIL'}") print("\n[3] 条目结构常数(entry base 99; total_bytes=null 变体 102)") e0 = ser(dict(pin_id="", reason="", kept_chars=0, total_chars=0, cut_at_bytes=0, total_bytes=0, unit="")) e0n = ser(dict(pin_id="", reason="", kept_chars=0, total_chars=0, cut_at_bytes=0, total_bytes=None, unit="")) print(f" base(all-zero)={len(e0)} base(total_bytes=null)={len(e0n)}") bad = 0; tot = 0 for p, line, d in rows: for e in d["truncation_points"]: tot += 1 eb = dict(e); eb["pin_id"] = ""; eb["reason"] = "" eb["kept_chars"] = eb["total_chars"] = eb["cut_at_bytes"] = 0 if "total_bytes" in eb: eb["total_bytes"] = 0 if eb["total_bytes"] is not None else None ebase = len(ser(eb)) add = (len(e["pin_id"]) - 2) + (len(e["reason"]) - 2) add += sum(len(str(e[kk])) - 1 for kk in ("kept_chars", "total_chars", "cut_at_bytes")) if e.get("total_bytes") is not None: add += len(str(e["total_bytes"])) - 1 else: add += 3 # null(4) 相对 0(1) if len(ser(e)) != ebase + add: bad += 1 print(f" 条目逐枚零残差: {tot-bad}/{tot}") print("\n[4] 容器字符/字节与 slack(饱和帧 = truncated 且 tp==N)") sat_chars = [] for p, line, d in rows: txt = io.open(p, encoding="utf-8").read() chars = len(txt); byts = os.path.getsize(p); slack = 18000 - chars sat = d["truncated"] and d["truncation_point_count"] == d["requested"] if sat: sat_chars.append(chars) print(f" {os.path.basename(p)[:26]} | sat={sat} | chars={chars} bytes={byts} slack={slack}") if sat_chars: import statistics print(f" 饱和帧字符: {sat_chars} mean={statistics.mean(sat_chars):.1f} dev_max={max(abs(c-17984) for c in sat_chars)} ({max(abs(c-17984) for c in sat_chars)/17984*100:.3f}%)") print("\n[5] 三枚必红臂(先证明会红)") # 取一枚 k=12 饱和帧做臂 target = next((p, line, d) for p, line, d in rows if len(d["truncation_points"]) == 12) p, line, d = target R = len(line); k = len(d["truncation_points"]) one_entry = len(ser(d["truncation_points"][0])) pred_missing = 35 + len(ser(dict(d, truncation_points=[]))) + sum(len(ser(e)) for e in d["truncation_points"][1:]) + max(k - 2, 0) print(f" A1 删一枚条目对象: 实测 R={R}, 按少一枚预测={pred_missing}, 偏差={R-pred_missing} (≈条目{one_entry}+逗号1) -> {'RED-OK' if R-pred_missing >= one_entry else 'NO-RED'}") d2 = dict(d); d2["x_injected"] = 0 R2 = len(PREFIX + ser(d2)) print(f" A2 骨架塞字段: 原 R={R}, 注入后实测={R2}, 结构常数偏移={R2-R} -> {'RED-OK' if R2-R > 0 else 'NO-RED'}") txt = io.open(p, encoding="utf-8").read() chars = len(txt); byts = os.path.getsize(p) print(f" A3 字节当字符: 容器字符={chars}<=18000 而字节={byts}>18000 -> 字节口径假超帽 {'RED-OK' if byts > 18000 >= chars else 'NO-RED'}")