From 5a3ea41a031ebe0cb2eefbc399c72a7c87bd60d1 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Mon, 27 Apr 2026 13:13:22 +0200 Subject: [PATCH] CLI changes --- src/tea3/cli.py | 6 +++++- src/tea3/variable_search.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tea3/cli.py b/src/tea3/cli.py index 1807739..2d5cca0 100644 --- a/src/tea3/cli.py +++ b/src/tea3/cli.py @@ -60,11 +60,15 @@ def run_classic_cli(): print("Done.") def run_exhaustive_cli(): + print("\nR registers are indexed 0–7; bits within each register are 0–7.") + print("Enter -1 to print all bits in the chosen register.") + steps = prompt_int("How many steps? (1–100): ", 1, 100) target_reg = prompt_int("Target register (0–7): ", 0, 7) + target_bit = prompt_int("Target bit (-1 or 0–7): ", -1, 7) print("-" * 50) - run_exhaustive(steps, target_reg) + run_exhaustive(steps, target_reg, target_bit) print("\n" + "=" * 50) print("Done.") diff --git a/src/tea3/variable_search.py b/src/tea3/variable_search.py index 6ff0fa0..9a5d157 100644 --- a/src/tea3/variable_search.py +++ b/src/tea3/variable_search.py @@ -25,7 +25,7 @@ def apply_variable_change(model, coeffs): new_R.append(row) return new_R -def run_exhaustive(steps: int, target_reg: int = 0): +def run_exhaustive(steps: int, target_reg: int = 0, target_bit: int = -1): model = Tea3Model() for _ in range(steps): model.step() @@ -37,6 +37,14 @@ def run_exhaustive(steps: int, target_reg: int = 0): label = "".join(map(str, coeffs)) print(f"\n[{idx:02d}] (a1,a2,a3,a4) = {label}") - for j in range(8): + + if target_bit == -1: + bits = range(8) + else: + if not (0 <= target_bit < 8): + raise ValueError("target_bit must be in [0, 7] or -1") + bits = [target_bit] + + for j in bits: poly = new_R[target_reg][j] print(f" R[{target_reg}][{j}] = {pretty_print(poly)}")