From 6920dc938906b1caef89ce0785ac62d97f71e1a6 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Tue, 21 Apr 2026 14:44:35 +0200 Subject: [PATCH] cli --- run_sage.sh | 2 +- src/tea3/cli.py | 44 +++++++++++++++++++++++++++++++++++++++++++ src/tea3/tea3model.py | 8 -------- 3 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 src/tea3/cli.py diff --git a/run_sage.sh b/run_sage.sh index 9eeadc7..4d1effb 100755 --- a/run_sage.sh +++ b/run_sage.sh @@ -1,2 +1,2 @@ #!/bin/bash -PYTHONPATH=src sage src/tea3/tea3model.py +PYTHONPATH=src sage src/tea3/cli.py diff --git a/src/tea3/cli.py b/src/tea3/cli.py new file mode 100644 index 0000000..bd55550 --- /dev/null +++ b/src/tea3/cli.py @@ -0,0 +1,44 @@ +from tea3.pretty_print import pretty_print +from tea3.tea3model import Tea3Model + + +def prompt_int(message: str, lo: int, hi: int) -> int: + while True: + raw = input(message).strip() + try: + value = int(raw) + except ValueError: + print("Please enter a whole number.") + continue + if lo <= value <= hi: + return value + print(f"Value must be between {lo} and {hi} (inclusive).") + + +def main() -> None: + print("=" * 50) + print(" Tea3 Model ") + print("=" * 50) + + steps = prompt_int("\nHow many steps do you want to run? (1–100): ", 1, 100) + + print("\nR registers are indexed 0–7; bits within each register are 0–7.") + reg = prompt_int("Which R register do you want to inspect? (0–7): ", 0, 7) + bit = prompt_int("Which bit of that register? (0–7): ", 0, 7) + + print(f"\nRunning {steps} step(s), watching R[{reg}][{bit}]") + print("-" * 50) + + model = Tea3Model(max_steps=steps) + + for i in range(steps): + model.step() + poly = model.R_bits[reg][bit] + print(f"\n[Step {i}] R_bits[{reg}][{bit}] =") + print(pretty_print(poly)) + + print("\n" + "=" * 50) + print("Done.") + + +main() diff --git a/src/tea3/tea3model.py b/src/tea3/tea3model.py index eb8d4a5..8970f0d 100644 --- a/src/tea3/tea3model.py +++ b/src/tea3/tea3model.py @@ -157,11 +157,3 @@ def F32(X, Y): x3*x4*y4 + x3*x4 + x3*y3 + x3*y4 + x4*y3*y4 + x4*y3 + x4 + y3*y4 + y3 + y4, x4*x5*y5 + x4*y4*y5 + x4*y4 + x5*y4*y5 + x5 + y4 + y5 + 1, ] - - -step = 5 -t = Tea3Model(step) -for i in range(step): - print("step "+str(i)) - t.step() - print(pretty_print(t.R_bits[0][0]))