Add audited non-additive Cipher-17 5M/5k dataset
Browse files- cipher17_nonadditive_5m/README.md +21 -0
- cipher17_nonadditive_5m/build_cipher17_nonadditive_test5k.py +229 -0
- cipher17_nonadditive_5m/create_data.py +265 -0
- cipher17_nonadditive_5m/create_data_provenance.txt +34 -0
- cipher17_nonadditive_5m/meta.pkl +3 -0
- cipher17_nonadditive_5m/publish_launcher.sh +156 -0
- cipher17_nonadditive_5m/test.bin +3 -0
- cipher17_nonadditive_5m/test5k_audit.json +24 -0
- cipher17_nonadditive_5m/test5k_provenance.txt +23 -0
- cipher17_nonadditive_5m/train.bin +3 -0
cipher17_nonadditive_5m/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cipher-17 Non-Additive 5M/5k
|
| 2 |
+
|
| 3 |
+
This package contains the harder non-additive member of the anchored Cipher-17 family.
|
| 4 |
+
|
| 5 |
+
- Vocabulary: decimal digits 0-9
|
| 6 |
+
- Sequence rule: n=17, k=5, c0=p0, ci=fi(pi,p(i+5 mod 17))
|
| 7 |
+
- Each position-specific fi is a fixed 10x10 Latin square stored in meta.pkl
|
| 8 |
+
- train.bin: 5,000,000 rows
|
| 9 |
+
- test.bin: 5,000 rows
|
| 10 |
+
- Row layout: 34 uint16 values, [17 ciphertext digits][17 plaintext digits]
|
| 11 |
+
- block_size: 34; vocab_size: 11
|
| 12 |
+
|
| 13 |
+
The first 1,000 test rows are byte-identical to the original generated test set. The remaining 4,000 rows use seed 42 and were checked to be unique and disjoint from the 5M training plaintexts. All 5,000 rows were exactly decoded with the saved maps.
|
| 14 |
+
|
| 15 |
+
SHA256:
|
| 16 |
+
|
| 17 |
+
- train.bin: cb6cd210dfc3266dc3c3ca16c813c8101bb076c56430c753425f409f2a26ed45
|
| 18 |
+
- test.bin: b7d8eceb88624c05c4d25e37d722875af8f2ef22a129c2a703735800ec0a0918
|
| 19 |
+
- meta.pkl: dbce00b19e96653338b3f32a8c30ee9df0a099a06e46bc2c17b7442d4050e9fe
|
| 20 |
+
|
| 21 |
+
See test5k_audit.json and the provenance files for the full checks and source versions.
|
cipher17_nonadditive_5m/build_cipher17_nonadditive_test5k.py
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Expand the fixed non-additive Cipher-17 test set from 1k to 5k.
|
| 3 |
+
|
| 4 |
+
The first 1,000 rows are preserved exactly. Four thousand deterministic rows
|
| 5 |
+
are generated with the saved Latin-square maps in ``meta.pkl`` and seed 42.
|
| 6 |
+
New plaintexts are required to be absent from both the 5M training set and the
|
| 7 |
+
preserved 1k test prefix.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import hashlib
|
| 14 |
+
import json
|
| 15 |
+
import pickle
|
| 16 |
+
import random
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
N = 17
|
| 23 |
+
K_OFFSET = 5
|
| 24 |
+
BLOCK_SIZE = 34
|
| 25 |
+
DTYPE = np.dtype(np.uint16)
|
| 26 |
+
POWERS_10 = np.asarray([10**power for power in range(N - 1, -1, -1)], dtype=np.uint64)
|
| 27 |
+
SOLVE_ORDER = [12, 7, 2, 14, 9, 4, 16, 11, 6, 1, 13, 8, 3, 15, 10, 5]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def sha256_file(path: Path, chunk_size: int = 8 * 1024 * 1024) -> str:
|
| 31 |
+
digest = hashlib.sha256()
|
| 32 |
+
with path.open("rb") as handle:
|
| 33 |
+
while chunk := handle.read(chunk_size):
|
| 34 |
+
digest.update(chunk)
|
| 35 |
+
return digest.hexdigest()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def row_count(path: Path) -> int:
|
| 39 |
+
row_bytes = BLOCK_SIZE * DTYPE.itemsize
|
| 40 |
+
size = path.stat().st_size
|
| 41 |
+
if size % row_bytes:
|
| 42 |
+
raise ValueError(f"{path} size {size} is not divisible by row size {row_bytes}")
|
| 43 |
+
return size // row_bytes
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def encode_plain_rows(rows: np.ndarray) -> np.ndarray:
|
| 47 |
+
plain = np.asarray(rows[:, N:BLOCK_SIZE], dtype=np.uint64)
|
| 48 |
+
return np.sum(plain * POWERS_10, axis=1, dtype=np.uint64)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def plain_key(plain: list[int]) -> int:
|
| 52 |
+
key = 0
|
| 53 |
+
for digit in plain:
|
| 54 |
+
key = key * 10 + digit
|
| 55 |
+
return key
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def validate_latin_maps(functions: list[list[list[int]]]) -> None:
|
| 59 |
+
if len(functions) != N:
|
| 60 |
+
raise ValueError(f"expected {N} functions, got {len(functions)}")
|
| 61 |
+
target = list(range(10))
|
| 62 |
+
for index, table in enumerate(functions):
|
| 63 |
+
arr = np.asarray(table)
|
| 64 |
+
if arr.shape != (10, 10):
|
| 65 |
+
raise ValueError(f"function {index} has shape {arr.shape}, expected (10, 10)")
|
| 66 |
+
if any(sorted(row.tolist()) != target for row in arr):
|
| 67 |
+
raise ValueError(f"function {index} has a non-permutation row")
|
| 68 |
+
if any(sorted(arr[:, column].tolist()) != target for column in range(10)):
|
| 69 |
+
raise ValueError(f"function {index} has a non-permutation column")
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def build_train_key_index(train: np.memmap, chunk_rows: int = 100_000) -> np.ndarray:
|
| 73 |
+
keys = np.empty(len(train), dtype=np.uint64)
|
| 74 |
+
for start in range(0, len(train), chunk_rows):
|
| 75 |
+
stop = min(start + chunk_rows, len(train))
|
| 76 |
+
keys[start:stop] = encode_plain_rows(train[start:stop])
|
| 77 |
+
keys.sort()
|
| 78 |
+
return keys
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def key_in_sorted(sorted_keys: np.ndarray, key: int) -> bool:
|
| 82 |
+
index = int(np.searchsorted(sorted_keys, np.uint64(key), side="left"))
|
| 83 |
+
return index < len(sorted_keys) and int(sorted_keys[index]) == key
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def encode_cipher(plain: list[int], functions: list[list[list[int]]]) -> list[int]:
|
| 87 |
+
cipher = [0] * N
|
| 88 |
+
cipher[0] = plain[0]
|
| 89 |
+
for index in range(1, N):
|
| 90 |
+
dependency = (index + K_OFFSET) % N
|
| 91 |
+
cipher[index] = int(functions[index][plain[index]][plain[dependency]])
|
| 92 |
+
return cipher
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def verify_rows(rows: np.ndarray, functions: list[list[list[int]]]) -> None:
|
| 96 |
+
for row_index, row in enumerate(rows):
|
| 97 |
+
cipher = [int(value) for value in row[:N]]
|
| 98 |
+
truth = [int(value) for value in row[N:BLOCK_SIZE]]
|
| 99 |
+
solved = [-1] * N
|
| 100 |
+
solved[0] = cipher[0]
|
| 101 |
+
for index in SOLVE_ORDER:
|
| 102 |
+
dependency = (index + K_OFFSET) % N
|
| 103 |
+
candidates = [
|
| 104 |
+
value
|
| 105 |
+
for value in range(10)
|
| 106 |
+
if functions[index][value][solved[dependency]] == cipher[index]
|
| 107 |
+
]
|
| 108 |
+
if len(candidates) != 1:
|
| 109 |
+
raise ValueError(
|
| 110 |
+
f"row {row_index}, index {index}: expected one inverse, got {candidates}"
|
| 111 |
+
)
|
| 112 |
+
solved[index] = candidates[0]
|
| 113 |
+
if solved != truth:
|
| 114 |
+
raise ValueError(f"row {row_index}: decoded plaintext does not match target")
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def main() -> None:
|
| 118 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 119 |
+
parser.add_argument("--data-dir", type=Path, required=True)
|
| 120 |
+
parser.add_argument("--source-test", type=Path, required=True)
|
| 121 |
+
parser.add_argument("--output", type=Path, required=True)
|
| 122 |
+
parser.add_argument("--audit", type=Path, required=True)
|
| 123 |
+
parser.add_argument("--seed", type=int, default=42)
|
| 124 |
+
parser.add_argument("--target-rows", type=int, default=5_000)
|
| 125 |
+
args = parser.parse_args()
|
| 126 |
+
|
| 127 |
+
data_dir = args.data_dir.resolve()
|
| 128 |
+
train_path = data_dir / "train.bin"
|
| 129 |
+
meta_path = data_dir / "meta.pkl"
|
| 130 |
+
source_test_path = args.source_test.resolve()
|
| 131 |
+
output_path = args.output.resolve()
|
| 132 |
+
audit_path = args.audit.resolve()
|
| 133 |
+
|
| 134 |
+
for required in (train_path, meta_path, source_test_path):
|
| 135 |
+
if not required.is_file():
|
| 136 |
+
raise FileNotFoundError(required)
|
| 137 |
+
|
| 138 |
+
train_rows = row_count(train_path)
|
| 139 |
+
source_rows = row_count(source_test_path)
|
| 140 |
+
if train_rows != 5_000_000:
|
| 141 |
+
raise ValueError(f"expected 5,000,000 train rows, got {train_rows}")
|
| 142 |
+
if source_rows != 1_000:
|
| 143 |
+
raise ValueError(f"expected 1,000 preserved test rows, got {source_rows}")
|
| 144 |
+
if args.target_rows < source_rows:
|
| 145 |
+
raise ValueError("target rows cannot be smaller than preserved source rows")
|
| 146 |
+
|
| 147 |
+
with meta_path.open("rb") as handle:
|
| 148 |
+
meta = pickle.load(handle)
|
| 149 |
+
if meta.get("block_size") != BLOCK_SIZE:
|
| 150 |
+
raise ValueError(f"unexpected block_size: {meta.get('block_size')}")
|
| 151 |
+
functions = meta["functions"]
|
| 152 |
+
validate_latin_maps(functions)
|
| 153 |
+
|
| 154 |
+
train = np.memmap(
|
| 155 |
+
train_path, dtype=DTYPE, mode="r", shape=(train_rows, BLOCK_SIZE)
|
| 156 |
+
)
|
| 157 |
+
source_test = np.memmap(
|
| 158 |
+
source_test_path, dtype=DTYPE, mode="r", shape=(source_rows, BLOCK_SIZE)
|
| 159 |
+
)
|
| 160 |
+
train_keys = build_train_key_index(train)
|
| 161 |
+
source_keys_array = encode_plain_rows(source_test)
|
| 162 |
+
source_keys = {int(key) for key in source_keys_array}
|
| 163 |
+
if len(source_keys) != source_rows:
|
| 164 |
+
raise ValueError("preserved 1k test contains duplicate plaintext rows")
|
| 165 |
+
train_overlap = sum(key_in_sorted(train_keys, key) for key in source_keys)
|
| 166 |
+
if train_overlap:
|
| 167 |
+
raise ValueError(f"preserved test overlaps train in {train_overlap} rows")
|
| 168 |
+
|
| 169 |
+
rng = random.Random(args.seed)
|
| 170 |
+
needed = args.target_rows - source_rows
|
| 171 |
+
generated_rows: list[list[int]] = []
|
| 172 |
+
rejected_train = 0
|
| 173 |
+
rejected_test = 0
|
| 174 |
+
while len(generated_rows) < needed:
|
| 175 |
+
plain = [rng.randrange(10) for _ in range(N)]
|
| 176 |
+
key = plain_key(plain)
|
| 177 |
+
if key in source_keys:
|
| 178 |
+
rejected_test += 1
|
| 179 |
+
continue
|
| 180 |
+
if key_in_sorted(train_keys, key):
|
| 181 |
+
rejected_train += 1
|
| 182 |
+
continue
|
| 183 |
+
source_keys.add(key)
|
| 184 |
+
generated_rows.append(encode_cipher(plain, functions) + plain)
|
| 185 |
+
|
| 186 |
+
combined = np.empty((args.target_rows, BLOCK_SIZE), dtype=DTYPE)
|
| 187 |
+
combined[:source_rows] = source_test
|
| 188 |
+
combined[source_rows:] = np.asarray(generated_rows, dtype=DTYPE)
|
| 189 |
+
verify_rows(combined, functions)
|
| 190 |
+
combined.tofile(output_path)
|
| 191 |
+
|
| 192 |
+
expected_bytes = args.target_rows * BLOCK_SIZE * DTYPE.itemsize
|
| 193 |
+
if output_path.stat().st_size != expected_bytes:
|
| 194 |
+
raise ValueError(
|
| 195 |
+
f"output size {output_path.stat().st_size} != expected {expected_bytes}"
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
audit = {
|
| 199 |
+
"task": "cipher17_nonadditive_test5k_expansion",
|
| 200 |
+
"n": N,
|
| 201 |
+
"k_offset": K_OFFSET,
|
| 202 |
+
"block_size": BLOCK_SIZE,
|
| 203 |
+
"dtype": "uint16",
|
| 204 |
+
"seed": args.seed,
|
| 205 |
+
"train_rows": train_rows,
|
| 206 |
+
"source_test_rows": source_rows,
|
| 207 |
+
"added_test_rows": needed,
|
| 208 |
+
"output_test_rows": args.target_rows,
|
| 209 |
+
"source_prefix_preserved": bool(
|
| 210 |
+
np.array_equal(combined[:source_rows], source_test)
|
| 211 |
+
),
|
| 212 |
+
"train_overlap_rows": 0,
|
| 213 |
+
"test_duplicate_rows": 0,
|
| 214 |
+
"rejected_train_candidates": rejected_train,
|
| 215 |
+
"rejected_test_candidates": rejected_test,
|
| 216 |
+
"latin_maps_validated": len(functions),
|
| 217 |
+
"decoded_rows_validated": args.target_rows,
|
| 218 |
+
"train_sha256": sha256_file(train_path),
|
| 219 |
+
"source_test_sha256": sha256_file(source_test_path),
|
| 220 |
+
"meta_sha256": sha256_file(meta_path),
|
| 221 |
+
"output_test_sha256": sha256_file(output_path),
|
| 222 |
+
"output_test_bytes": output_path.stat().st_size,
|
| 223 |
+
}
|
| 224 |
+
audit_path.write_text(json.dumps(audit, indent=2) + "\n", encoding="utf-8")
|
| 225 |
+
print(json.dumps(audit, indent=2))
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
if __name__ == "__main__":
|
| 229 |
+
main()
|
cipher17_nonadditive_5m/create_data.py
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
import numpy
|
| 5 |
+
import pickle
|
| 6 |
+
|
| 7 |
+
n = 17 # 长度改为 13
|
| 8 |
+
k_offset = 5 # 步长 (与 13 互质)
|
| 9 |
+
num_train = 5000000
|
| 10 |
+
num_test = 1000
|
| 11 |
+
|
| 12 |
+
# 一个固定的、按位置变化的常量,扩展到 13 位
|
| 13 |
+
# (来自圆周率,只是为了固定且看起来随机)
|
| 14 |
+
pos_const = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2] # 扩展了一位
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import random
|
| 19 |
+
from typing import List, Tuple, Set, Optional
|
| 20 |
+
|
| 21 |
+
Latin = List[List[int]]
|
| 22 |
+
|
| 23 |
+
def cyclic_latin_square(n: int = 10) -> Latin:
|
| 24 |
+
return [[(i + j) % n for j in range(n)] for i in range(n)]
|
| 25 |
+
|
| 26 |
+
def is_latin_square(L: Latin) -> bool:
|
| 27 |
+
n = len(L)
|
| 28 |
+
target = set(range(n))
|
| 29 |
+
for i in range(n):
|
| 30 |
+
if set(L[i]) != target:
|
| 31 |
+
return False
|
| 32 |
+
for j in range(n):
|
| 33 |
+
col = {L[i][j] for i in range(n)}
|
| 34 |
+
if col != target:
|
| 35 |
+
return False
|
| 36 |
+
return True
|
| 37 |
+
|
| 38 |
+
def _try_random_intercalate_move(L: Latin, rng: random.Random) -> bool:
|
| 39 |
+
"""
|
| 40 |
+
Try one random 2x2 intercalate flip. Return True if moved, else False.
|
| 41 |
+
"""
|
| 42 |
+
n = len(L)
|
| 43 |
+
r1, r2 = rng.sample(range(n), 2)
|
| 44 |
+
c1, c2 = rng.sample(range(n), 2)
|
| 45 |
+
|
| 46 |
+
a = L[r1][c1]
|
| 47 |
+
b = L[r1][c2]
|
| 48 |
+
if a == b:
|
| 49 |
+
return False
|
| 50 |
+
|
| 51 |
+
# Need the 2x2 pattern:
|
| 52 |
+
# L[r1,c1]=a, L[r1,c2]=b
|
| 53 |
+
# L[r2,c1]=b, L[r2,c2]=a
|
| 54 |
+
if L[r2][c1] != b or L[r2][c2] != a:
|
| 55 |
+
return False
|
| 56 |
+
|
| 57 |
+
# Flip to:
|
| 58 |
+
# b a
|
| 59 |
+
# a b
|
| 60 |
+
L[r1][c1], L[r1][c2] = b, a
|
| 61 |
+
L[r2][c1], L[r2][c2] = a, b
|
| 62 |
+
return True
|
| 63 |
+
|
| 64 |
+
def mcmc_step(L: Latin, rng: random.Random, lazy_p: float = 0.1, max_trials: int = 200) -> None:
|
| 65 |
+
"""
|
| 66 |
+
One Markov step:
|
| 67 |
+
- with probability lazy_p: do nothing (aperiodicity)
|
| 68 |
+
- else: attempt up to max_trials random intercalate moves; if none found, do nothing
|
| 69 |
+
"""
|
| 70 |
+
if rng.random() < lazy_p:
|
| 71 |
+
return
|
| 72 |
+
for _ in range(max_trials):
|
| 73 |
+
if _try_random_intercalate_move(L, rng):
|
| 74 |
+
return
|
| 75 |
+
# No valid move found in trials -> stay
|
| 76 |
+
|
| 77 |
+
def sample_latin_square_10(
|
| 78 |
+
rng: random.Random,
|
| 79 |
+
burn_in: int = 50_000,
|
| 80 |
+
steps_after: int = 20_000,
|
| 81 |
+
lazy_p: float = 0.1,
|
| 82 |
+
max_trials_per_step: int = 200
|
| 83 |
+
) -> Latin:
|
| 84 |
+
"""
|
| 85 |
+
Start from cyclic Latin square and run MCMC.
|
| 86 |
+
Return one approximately-uniform sample.
|
| 87 |
+
"""
|
| 88 |
+
L = cyclic_latin_square(10)
|
| 89 |
+
|
| 90 |
+
# Burn-in
|
| 91 |
+
for _ in range(burn_in):
|
| 92 |
+
mcmc_step(L, rng, lazy_p=lazy_p, max_trials=max_trials_per_step)
|
| 93 |
+
|
| 94 |
+
# Extra steps (thinning / further mixing)
|
| 95 |
+
for _ in range(steps_after):
|
| 96 |
+
mcmc_step(L, rng, lazy_p=lazy_p, max_trials=max_trials_per_step)
|
| 97 |
+
|
| 98 |
+
return [row[:] for row in L]
|
| 99 |
+
|
| 100 |
+
def make_functions(
|
| 101 |
+
n: int,
|
| 102 |
+
seed: Optional[int] = None,
|
| 103 |
+
burn_in: int = 500000,
|
| 104 |
+
steps_between_samples: int = 500000,
|
| 105 |
+
lazy_p: float = 0.1,
|
| 106 |
+
max_trials_per_step: int = 200
|
| 107 |
+
) -> List[Latin]:
|
| 108 |
+
"""
|
| 109 |
+
Generate n distinct 10x10 Latin squares via MCMC (approx uniform).
|
| 110 |
+
Distinctness is enforced by hashing full matrices.
|
| 111 |
+
"""
|
| 112 |
+
rng = random.Random(seed)
|
| 113 |
+
out: List[Latin] = []
|
| 114 |
+
seen: Set[Tuple[Tuple[int, ...], ...]] = set()
|
| 115 |
+
|
| 116 |
+
# We keep one chain running and take samples separated by steps_between_samples.
|
| 117 |
+
L = cyclic_latin_square(10)
|
| 118 |
+
|
| 119 |
+
# burn-in on the running chain
|
| 120 |
+
for _ in range(burn_in):
|
| 121 |
+
mcmc_step(L, rng, lazy_p=lazy_p, max_trials=max_trials_per_step)
|
| 122 |
+
|
| 123 |
+
while len(out) < n:
|
| 124 |
+
# advance chain
|
| 125 |
+
for _ in range(steps_between_samples):
|
| 126 |
+
mcmc_step(L, rng, lazy_p=lazy_p, max_trials=max_trials_per_step)
|
| 127 |
+
|
| 128 |
+
sample = [row[:] for row in L]
|
| 129 |
+
key = tuple(tuple(row) for row in sample)
|
| 130 |
+
if key in seen:
|
| 131 |
+
continue
|
| 132 |
+
# Safety check (can be removed for speed)
|
| 133 |
+
if not is_latin_square(sample):
|
| 134 |
+
raise RuntimeError("Internal error: produced a non-Latin square (should not happen).")
|
| 135 |
+
|
| 136 |
+
seen.add(key)
|
| 137 |
+
out.append(sample)
|
| 138 |
+
|
| 139 |
+
return out
|
| 140 |
+
|
| 141 |
+
functions = make_functions(n=n)
|
| 142 |
+
|
| 143 |
+
print(functions)
|
| 144 |
+
|
| 145 |
+
#print(xxx)
|
| 146 |
+
|
| 147 |
+
def generate_samples_anchored_global(num_samples):
|
| 148 |
+
samples = []
|
| 149 |
+
|
| 150 |
+
vocab = '0123456789'
|
| 151 |
+
for _ in range(num_samples):
|
| 152 |
+
# 1. 随机明文 (数字列表)
|
| 153 |
+
plain_digits = [random.randint(0, 9) for _ in range(n)]
|
| 154 |
+
|
| 155 |
+
cipher_digits = [0] * n
|
| 156 |
+
|
| 157 |
+
# 2. 设置“锚点”
|
| 158 |
+
# cipher[0] = plain[0]
|
| 159 |
+
cipher_digits[0] = plain_digits[0]
|
| 160 |
+
|
| 161 |
+
# 3. 生成全局依赖
|
| 162 |
+
for i in range(1, n):
|
| 163 |
+
# cipher[i] = (plain[i] + plain[(i + k) % n] + C[i]) % 10
|
| 164 |
+
j = (i + k_offset) % n
|
| 165 |
+
val = functions[i][plain_digits[i]][plain_digits[j]]
|
| 166 |
+
#(plain_digits[i] + plain_digits[j] + pos_const[i]) % 10
|
| 167 |
+
cipher_digits[i] = val
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
# 转换回字符串
|
| 171 |
+
#plain_str = ''.join(map(str, plain_digits))
|
| 172 |
+
#cipher_str = ''.join(map(str, cipher_digits))
|
| 173 |
+
|
| 174 |
+
#samples.append({"input": cipher_str, "output": plain_str})
|
| 175 |
+
samples.append(cipher_digits+plain_digits)
|
| 176 |
+
#test_samples.append(cipher_digits+plain_digits)
|
| 177 |
+
|
| 178 |
+
return numpy.array(samples,dtype=numpy.uint16)
|
| 179 |
+
|
| 180 |
+
# --- 生成文件 ---
|
| 181 |
+
train_samples = generate_samples_anchored_global(num_train)
|
| 182 |
+
|
| 183 |
+
print(train_samples[0])
|
| 184 |
+
#print(xxx)
|
| 185 |
+
train_samples.tofile('train.bin')
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
#with open(f'{n}_anchored_global_mod10_train.jsonl', 'w') as f:
|
| 189 |
+
# for s in train_samples:
|
| 190 |
+
# f.write(json.dumps(s) + '\n')
|
| 191 |
+
|
| 192 |
+
test_samples = generate_samples_anchored_global(num_test)
|
| 193 |
+
test_samples.tofile('test.bin')
|
| 194 |
+
#with open(f'{n}_anchored_global_mod10_test.jsonl', 'w') as f:
|
| 195 |
+
# for s in test_samples:
|
| 196 |
+
# f.write(json.dumps(s) + '\n')
|
| 197 |
+
|
| 198 |
+
print(f"Generated {num_train} train samples and {num_test} test samples for ANCHORED GLOBAL (mod 10) task.")
|
| 199 |
+
print(f"n={n}, k_offset={k_offset}")
|
| 200 |
+
|
| 201 |
+
meta = {
|
| 202 |
+
'vocab_size': 11,
|
| 203 |
+
'block_size': n * 2,
|
| 204 |
+
'functions': functions
|
| 205 |
+
}
|
| 206 |
+
with open('meta.pkl', 'wb') as f:
|
| 207 |
+
pickle.dump(meta, f)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
# --- 验证逻辑 ---
|
| 212 |
+
# 打印一个样本的解密过程,用于验证
|
| 213 |
+
print("\n--- Verification Sample ---")
|
| 214 |
+
if test_samples is None:
|
| 215 |
+
print("No test samples generated for verification.")
|
| 216 |
+
else:
|
| 217 |
+
|
| 218 |
+
for t in range(len(test_samples)):
|
| 219 |
+
c_str = test_samples[0,0:n]
|
| 220 |
+
p_str = test_samples[0,n:2*n]
|
| 221 |
+
#print(f"Cipher: {c_str}")
|
| 222 |
+
#print(f"Plain: {p_str}")
|
| 223 |
+
|
| 224 |
+
# 手动验证解密链
|
| 225 |
+
c = [int(x) for x in c_str]
|
| 226 |
+
p_actual = [int(x) for x in p_str]
|
| 227 |
+
p_solved = [-1] * n # -1 表示未知
|
| 228 |
+
|
| 229 |
+
#print("\nSolving sequence (MDM's perspective):")
|
| 230 |
+
p_solved[0] = c[0]
|
| 231 |
+
#print(f"Step 0: Solved p[0] = c[0] = {p_solved[0]}")
|
| 232 |
+
|
| 233 |
+
# (n=13, k=5) 的求解顺序
|
| 234 |
+
# 求解 p[i] 需要 p[(i+k)%n]
|
| 235 |
+
# 反过来看,p[0] -> p[i] s.t. (i+5)%13 = 0 => i = 8
|
| 236 |
+
# p[8] -> p[i] s.t. (i+5)%13 = 8 => i = 3
|
| 237 |
+
# p[3] -> p[i] s.t. (i+5)%13 = 3 => i = -2 % 13 = 11
|
| 238 |
+
# 链条: 0 -> 8 -> 3 -> 11 -> 6 -> 1 -> 9 -> 4 -> 12 -> 7 -> 2 -> 10 -> 5
|
| 239 |
+
solve_order = [12, 7, 2, 14, 9, 4, 16, 11, 6, 1, 13, 8, 3, 15, 10, 5]
|
| 240 |
+
|
| 241 |
+
for i_solve in solve_order:
|
| 242 |
+
# 找到它依赖谁
|
| 243 |
+
i_depend_on = (i_solve + k_offset) % n
|
| 244 |
+
# plain[i] = (cipher[i] - plain[j] - C[i]) % 10
|
| 245 |
+
val = -1
|
| 246 |
+
for j in range(10):
|
| 247 |
+
if functions[i_solve][j][p_solved[i_depend_on]] == c[i_solve]:
|
| 248 |
+
val = j
|
| 249 |
+
break
|
| 250 |
+
if(val == -1):
|
| 251 |
+
print("Oh no, what happens!")
|
| 252 |
+
|
| 253 |
+
#(c[i_solve] - p_solved[i_depend_on] - pos_const[i_solve]) % 10
|
| 254 |
+
p_solved[i_solve] = val
|
| 255 |
+
#print(f"Step N: Solved p[{i_solve}] = (c[{i_solve}] - p[{i_depend_on}] - C[{i_solve}]) % 10 = {val}")
|
| 256 |
+
|
| 257 |
+
#print("\nSolved Plain:", numpy.array(p_solved))
|
| 258 |
+
#print("Actual Plain:", p_str)
|
| 259 |
+
|
| 260 |
+
if (p_str == numpy.array(p_solved)).all():
|
| 261 |
+
#print("Verification SUCCESSFUL.")
|
| 262 |
+
continue
|
| 263 |
+
else:
|
| 264 |
+
print("Verification FAILED.")
|
| 265 |
+
print(xxxxx)
|
cipher17_nonadditive_5m/create_data_provenance.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
task=cipher17_nonadditive_create_data
|
| 2 |
+
task_type=cpu_only
|
| 3 |
+
status=starting
|
| 4 |
+
machine=DESKTOP-KB6AIKM
|
| 5 |
+
run_id=20260811_165314
|
| 6 |
+
source_script=/e/code/Kits/Projects/self-evolving-trajectories-private/create_data.py
|
| 7 |
+
source_sha256=a5dfa24cf9f4d970a0fa7b2658fb666e74168c2619f7b461a9195b93a2332ea7
|
| 8 |
+
branch=codex/serfox-compile-stability-20260726
|
| 9 |
+
commit=c87090214afac547d6f7e42212bbe2f4ac876506
|
| 10 |
+
git_dirty=dirty
|
| 11 |
+
python_bin=python
|
| 12 |
+
python_args=-S
|
| 13 |
+
pythonpath=/d/code/anaconda/Lib/site-packages
|
| 14 |
+
python_version=Python 3.9.13
|
| 15 |
+
output_dir=/f/Dataset/DLLM_dataset
|
| 16 |
+
log_path=/f/Dataset/DLLM_dataset/create_data_cipher17_nonadditive_20260811_165314.log
|
| 17 |
+
run_command_original=cd "/f/Dataset/DLLM_dataset" && PYTHONPATH="/d/code/anaconda/Lib/site-packages" "python" -S "/e/code/Kits/Projects/self-evolving-trajectories-private/create_data.py"
|
| 18 |
+
config_n=17
|
| 19 |
+
config_k_offset=5
|
| 20 |
+
config_num_train=5000000
|
| 21 |
+
config_num_test=1000
|
| 22 |
+
config_dtype=uint16
|
| 23 |
+
expected_train_bytes=340000000
|
| 24 |
+
expected_test_bytes=68000
|
| 25 |
+
status=completed
|
| 26 |
+
generator_exit_code=0
|
| 27 |
+
train_path=/f/Dataset/DLLM_dataset/train.bin
|
| 28 |
+
test_path=/f/Dataset/DLLM_dataset/test.bin
|
| 29 |
+
meta_path=/f/Dataset/DLLM_dataset/meta.pkl
|
| 30 |
+
train_bytes=340000000
|
| 31 |
+
test_bytes=68000
|
| 32 |
+
train_sha256=cb6cd210dfc3266dc3c3ca16c813c8101bb076c56430c753425f409f2a26ed45
|
| 33 |
+
test_sha256=756281dfc7b0fb8178287ced37ea247c85ede409970da01a43417ff2497a33fa
|
| 34 |
+
meta_sha256=dbce00b19e96653338b3f32a8c30ee9df0a099a06e46bc2c17b7442d4050e9fe
|
cipher17_nonadditive_5m/meta.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dbce00b19e96653338b3f32a8c30ee9df0a099a06e46bc2c17b7442d4050e9fe
|
| 3 |
+
size 4210
|
cipher17_nonadditive_5m/publish_launcher.sh
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
| 5 |
+
DATA_DIR="${DLLM_DATASET_DIR:-/f/Dataset/DLLM_dataset}"
|
| 6 |
+
HF_REPO_ID="${HF_REPO_ID:-zeyuzy/DLLM-Planing-Task}"
|
| 7 |
+
HF_REPO_PREFIX="${HF_REPO_PREFIX:-cipher17_nonadditive_5m}"
|
| 8 |
+
PYTHON_BIN="${PYTHON_BIN:-python}"
|
| 9 |
+
PYTHONPATH_EXTRA="/d/code/anaconda/Lib/site-packages"
|
| 10 |
+
export PYTHONPATH="$PYTHONPATH_EXTRA${PYTHONPATH:+:$PYTHONPATH}"
|
| 11 |
+
PYTHON_ARGS=(-S)
|
| 12 |
+
|
| 13 |
+
TRAIN_PATH="$DATA_DIR/train.bin"
|
| 14 |
+
TEST_PATH="$DATA_DIR/test.bin"
|
| 15 |
+
META_PATH="$DATA_DIR/meta.pkl"
|
| 16 |
+
TEST1K_BACKUP="$DATA_DIR/test1k_original.bin"
|
| 17 |
+
TEST5K_TMP="$DATA_DIR/test5k.bin.tmp"
|
| 18 |
+
AUDIT_PATH="$DATA_DIR/cipher17_nonadditive_test5k_audit.json"
|
| 19 |
+
AUDIT_TMP="$DATA_DIR/cipher17_nonadditive_test5k_audit.json.tmp"
|
| 20 |
+
README_PATH="$DATA_DIR/cipher17_nonadditive_5m_README.md"
|
| 21 |
+
PROV_PATH="$DATA_DIR/cipher17_nonadditive_test5k_provenance.txt"
|
| 22 |
+
RUN_ID="$(date +%Y%m%d_%H%M%S)"
|
| 23 |
+
LOG_PATH="$DATA_DIR/cipher17_nonadditive_test5k_hf_${RUN_ID}.log"
|
| 24 |
+
|
| 25 |
+
EXPECTED_TRAIN_SHA="cb6cd210dfc3266dc3c3ca16c813c8101bb076c56430c753425f409f2a26ed45"
|
| 26 |
+
EXPECTED_META_SHA="dbce00b19e96653338b3f32a8c30ee9df0a099a06e46bc2c17b7442d4050e9fe"
|
| 27 |
+
EXPECTED_TEST1K_SHA="756281dfc7b0fb8178287ced37ea247c85ede409970da01a43417ff2497a33fa"
|
| 28 |
+
|
| 29 |
+
die() {
|
| 30 |
+
printf 'ERROR: %s\n' "$*" >&2
|
| 31 |
+
exit 1
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
sha_of() {
|
| 35 |
+
sha256sum "$1" | awk '{print $1}'
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
[[ -f "$TRAIN_PATH" ]] || die "missing $TRAIN_PATH"
|
| 39 |
+
[[ -f "$TEST_PATH" ]] || die "missing $TEST_PATH"
|
| 40 |
+
[[ -f "$META_PATH" ]] || die "missing $META_PATH"
|
| 41 |
+
[[ "$(sha_of "$TRAIN_PATH")" == "$EXPECTED_TRAIN_SHA" ]] || die "train hash drift"
|
| 42 |
+
[[ "$(sha_of "$META_PATH")" == "$EXPECTED_META_SHA" ]] || die "meta hash drift"
|
| 43 |
+
|
| 44 |
+
CURRENT_TEST_BYTES="$(stat -c%s "$TEST_PATH")"
|
| 45 |
+
if [[ "$CURRENT_TEST_BYTES" == "68000" ]]; then
|
| 46 |
+
[[ "$(sha_of "$TEST_PATH")" == "$EXPECTED_TEST1K_SHA" ]] || die "source test1k hash drift"
|
| 47 |
+
if [[ -e "$TEST1K_BACKUP" ]]; then
|
| 48 |
+
[[ "$(sha_of "$TEST1K_BACKUP")" == "$EXPECTED_TEST1K_SHA" ]] || die "existing test1k backup hash drift"
|
| 49 |
+
else
|
| 50 |
+
cp -p "$TEST_PATH" "$TEST1K_BACKUP"
|
| 51 |
+
fi
|
| 52 |
+
rm -f "$TEST5K_TMP" "$AUDIT_TMP"
|
| 53 |
+
"$PYTHON_BIN" "${PYTHON_ARGS[@]}" \
|
| 54 |
+
"$REPO_ROOT/data/build_cipher17_nonadditive_test5k.py" \
|
| 55 |
+
--data-dir "$DATA_DIR" \
|
| 56 |
+
--source-test "$TEST1K_BACKUP" \
|
| 57 |
+
--output "$TEST5K_TMP" \
|
| 58 |
+
--audit "$AUDIT_TMP" \
|
| 59 |
+
--seed 42 \
|
| 60 |
+
--target-rows 5000
|
| 61 |
+
[[ "$(stat -c%s "$TEST5K_TMP")" == "340000" ]] || die "generated test5k size mismatch"
|
| 62 |
+
mv "$TEST5K_TMP" "$TEST_PATH"
|
| 63 |
+
mv "$AUDIT_TMP" "$AUDIT_PATH"
|
| 64 |
+
elif [[ "$CURRENT_TEST_BYTES" == "340000" ]]; then
|
| 65 |
+
[[ -f "$TEST1K_BACKUP" ]] || die "test is already 5k but preserved test1k backup is missing"
|
| 66 |
+
[[ -f "$AUDIT_PATH" ]] || die "test is already 5k but audit is missing"
|
| 67 |
+
[[ "$(sha_of "$TEST1K_BACKUP")" == "$EXPECTED_TEST1K_SHA" ]] || die "test1k backup hash drift"
|
| 68 |
+
else
|
| 69 |
+
die "unexpected test.bin size: $CURRENT_TEST_BYTES"
|
| 70 |
+
fi
|
| 71 |
+
|
| 72 |
+
TEST5K_SHA="$(sha_of "$TEST_PATH")"
|
| 73 |
+
BRANCH="$(git -C "$REPO_ROOT" branch --show-current)"
|
| 74 |
+
COMMIT="$(git -C "$REPO_ROOT" rev-parse HEAD)"
|
| 75 |
+
SOURCE_SHA="$(sha_of "$REPO_ROOT/create_data.py")"
|
| 76 |
+
BUILDER_SHA="$(sha_of "$REPO_ROOT/data/build_cipher17_nonadditive_test5k.py")"
|
| 77 |
+
|
| 78 |
+
cat > "$README_PATH" <<EOF
|
| 79 |
+
# Cipher-17 Non-Additive 5M/5k
|
| 80 |
+
|
| 81 |
+
This package contains the harder non-additive member of the anchored Cipher-17 family.
|
| 82 |
+
|
| 83 |
+
- Vocabulary: decimal digits 0-9
|
| 84 |
+
- Sequence rule: n=17, k=5, c0=p0, ci=fi(pi,p(i+5 mod 17))
|
| 85 |
+
- Each position-specific fi is a fixed 10x10 Latin square stored in meta.pkl
|
| 86 |
+
- train.bin: 5,000,000 rows
|
| 87 |
+
- test.bin: 5,000 rows
|
| 88 |
+
- Row layout: 34 uint16 values, [17 ciphertext digits][17 plaintext digits]
|
| 89 |
+
- block_size: 34; vocab_size: 11
|
| 90 |
+
|
| 91 |
+
The first 1,000 test rows are byte-identical to the original generated test set. The remaining 4,000 rows use seed 42 and were checked to be unique and disjoint from the 5M training plaintexts. All 5,000 rows were exactly decoded with the saved maps.
|
| 92 |
+
|
| 93 |
+
SHA256:
|
| 94 |
+
|
| 95 |
+
- train.bin: $EXPECTED_TRAIN_SHA
|
| 96 |
+
- test.bin: $TEST5K_SHA
|
| 97 |
+
- meta.pkl: $EXPECTED_META_SHA
|
| 98 |
+
|
| 99 |
+
See test5k_audit.json and the provenance files for the full checks and source versions.
|
| 100 |
+
EOF
|
| 101 |
+
|
| 102 |
+
cat > "$PROV_PATH" <<EOF
|
| 103 |
+
task=cipher17_nonadditive_test5k_and_hf_publish
|
| 104 |
+
task_type=cpu_only_external_upload
|
| 105 |
+
status=prepared
|
| 106 |
+
machine=$(hostname)
|
| 107 |
+
run_id=$RUN_ID
|
| 108 |
+
branch=$BRANCH
|
| 109 |
+
commit=$COMMIT
|
| 110 |
+
git_dirty=$(git -C "$REPO_ROOT" status --porcelain | wc -l)
|
| 111 |
+
data_dir=$DATA_DIR
|
| 112 |
+
hf_repo_id=$HF_REPO_ID
|
| 113 |
+
hf_repo_prefix=$HF_REPO_PREFIX
|
| 114 |
+
source_script=$REPO_ROOT/create_data.py
|
| 115 |
+
source_sha256=$SOURCE_SHA
|
| 116 |
+
builder_script=$REPO_ROOT/data/build_cipher17_nonadditive_test5k.py
|
| 117 |
+
builder_sha256=$BUILDER_SHA
|
| 118 |
+
train_sha256=$EXPECTED_TRAIN_SHA
|
| 119 |
+
test1k_backup_sha256=$EXPECTED_TEST1K_SHA
|
| 120 |
+
test5k_sha256=$TEST5K_SHA
|
| 121 |
+
meta_sha256=$EXPECTED_META_SHA
|
| 122 |
+
test5k_rows=5000
|
| 123 |
+
test5k_bytes=$(stat -c%s "$TEST_PATH")
|
| 124 |
+
audit_path=$AUDIT_PATH
|
| 125 |
+
log_path=$LOG_PATH
|
| 126 |
+
EOF
|
| 127 |
+
|
| 128 |
+
set +e
|
| 129 |
+
"$PYTHON_BIN" "${PYTHON_ARGS[@]}" \
|
| 130 |
+
"$REPO_ROOT/scripts/experiments/upload_cipher17_nonadditive_hf.py" \
|
| 131 |
+
--repo-id "$HF_REPO_ID" \
|
| 132 |
+
--repo-prefix "$HF_REPO_PREFIX" \
|
| 133 |
+
--data-dir "$DATA_DIR" \
|
| 134 |
+
--repo-root "$REPO_ROOT" \
|
| 135 |
+
2>&1 | tee "$LOG_PATH"
|
| 136 |
+
UPLOAD_STATUS=${PIPESTATUS[0]}
|
| 137 |
+
set -e
|
| 138 |
+
|
| 139 |
+
if [[ "$UPLOAD_STATUS" -ne 0 ]]; then
|
| 140 |
+
{
|
| 141 |
+
printf 'status=upload_failed\n'
|
| 142 |
+
printf 'upload_exit_code=%s\n' "$UPLOAD_STATUS"
|
| 143 |
+
} >> "$PROV_PATH"
|
| 144 |
+
exit "$UPLOAD_STATUS"
|
| 145 |
+
fi
|
| 146 |
+
|
| 147 |
+
COMMIT_OID="$(grep -m1 '"commit_oid"' "$LOG_PATH" | sed -E 's/.*"commit_oid": "([^"]+)".*/\1/')"
|
| 148 |
+
COMMIT_URL="$(grep -m1 '"commit_url"' "$LOG_PATH" | sed -E 's/.*"commit_url": "([^"]+)".*/\1/')"
|
| 149 |
+
{
|
| 150 |
+
printf 'status=completed\n'
|
| 151 |
+
printf 'upload_exit_code=0\n'
|
| 152 |
+
printf 'hf_commit_oid=%s\n' "$COMMIT_OID"
|
| 153 |
+
printf 'hf_commit_url=%s\n' "$COMMIT_URL"
|
| 154 |
+
} >> "$PROV_PATH"
|
| 155 |
+
|
| 156 |
+
printf 'Prepared test5k and uploaded HF package successfully.\n'
|
cipher17_nonadditive_5m/test.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b7d8eceb88624c05c4d25e37d722875af8f2ef22a129c2a703735800ec0a0918
|
| 3 |
+
size 340000
|
cipher17_nonadditive_5m/test5k_audit.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "cipher17_nonadditive_test5k_expansion",
|
| 3 |
+
"n": 17,
|
| 4 |
+
"k_offset": 5,
|
| 5 |
+
"block_size": 34,
|
| 6 |
+
"dtype": "uint16",
|
| 7 |
+
"seed": 42,
|
| 8 |
+
"train_rows": 5000000,
|
| 9 |
+
"source_test_rows": 1000,
|
| 10 |
+
"added_test_rows": 4000,
|
| 11 |
+
"output_test_rows": 5000,
|
| 12 |
+
"source_prefix_preserved": true,
|
| 13 |
+
"train_overlap_rows": 0,
|
| 14 |
+
"test_duplicate_rows": 0,
|
| 15 |
+
"rejected_train_candidates": 0,
|
| 16 |
+
"rejected_test_candidates": 0,
|
| 17 |
+
"latin_maps_validated": 17,
|
| 18 |
+
"decoded_rows_validated": 5000,
|
| 19 |
+
"train_sha256": "cb6cd210dfc3266dc3c3ca16c813c8101bb076c56430c753425f409f2a26ed45",
|
| 20 |
+
"source_test_sha256": "756281dfc7b0fb8178287ced37ea247c85ede409970da01a43417ff2497a33fa",
|
| 21 |
+
"meta_sha256": "dbce00b19e96653338b3f32a8c30ee9df0a099a06e46bc2c17b7442d4050e9fe",
|
| 22 |
+
"output_test_sha256": "b7d8eceb88624c05c4d25e37d722875af8f2ef22a129c2a703735800ec0a0918",
|
| 23 |
+
"output_test_bytes": 340000
|
| 24 |
+
}
|
cipher17_nonadditive_5m/test5k_provenance.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
task=cipher17_nonadditive_test5k_and_hf_publish
|
| 2 |
+
task_type=cpu_only_external_upload
|
| 3 |
+
status=prepared
|
| 4 |
+
machine=DESKTOP-KB6AIKM
|
| 5 |
+
run_id=20260811_192947
|
| 6 |
+
branch=codex/serfox-compile-stability-20260726
|
| 7 |
+
commit=c8aa0ff3887b2e6a575971c5f288d2afc812f111
|
| 8 |
+
git_dirty=98
|
| 9 |
+
data_dir=/f/Dataset/DLLM_dataset
|
| 10 |
+
hf_repo_id=zeyuzy/DLLM-Planing-Task
|
| 11 |
+
hf_repo_prefix=cipher17_nonadditive_5m
|
| 12 |
+
source_script=/e/code/Kits/Projects/self-evolving-trajectories-private/create_data.py
|
| 13 |
+
source_sha256=a5dfa24cf9f4d970a0fa7b2658fb666e74168c2619f7b461a9195b93a2332ea7
|
| 14 |
+
builder_script=/e/code/Kits/Projects/self-evolving-trajectories-private/data/build_cipher17_nonadditive_test5k.py
|
| 15 |
+
builder_sha256=e23f1bb889611c3fc3dccea7cca5dcd9a5fc1011fe48067d68d698057c9fd2db
|
| 16 |
+
train_sha256=cb6cd210dfc3266dc3c3ca16c813c8101bb076c56430c753425f409f2a26ed45
|
| 17 |
+
test1k_backup_sha256=756281dfc7b0fb8178287ced37ea247c85ede409970da01a43417ff2497a33fa
|
| 18 |
+
test5k_sha256=b7d8eceb88624c05c4d25e37d722875af8f2ef22a129c2a703735800ec0a0918
|
| 19 |
+
meta_sha256=dbce00b19e96653338b3f32a8c30ee9df0a099a06e46bc2c17b7442d4050e9fe
|
| 20 |
+
test5k_rows=5000
|
| 21 |
+
test5k_bytes=340000
|
| 22 |
+
audit_path=/f/Dataset/DLLM_dataset/cipher17_nonadditive_test5k_audit.json
|
| 23 |
+
log_path=/f/Dataset/DLLM_dataset/cipher17_nonadditive_test5k_hf_20260811_192947.log
|
cipher17_nonadditive_5m/train.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb6cd210dfc3266dc3c3ca16c813c8101bb076c56430c753425f409f2a26ed45
|
| 3 |
+
size 340000000
|