remove ambiguous unicode char

This commit is contained in:
2026-07-13 16:46:22 +02:00
parent 9cc94687bc
commit 8961e98a01
3 changed files with 41 additions and 41 deletions
+37 -37
View File
@@ -12,12 +12,12 @@ from tea3.precompute import run_precompute_cli, run_load_cli
def run_classic_cli(): def run_classic_cli():
print("\nR registers are indexed 07; bits within each register are 07.") print("\nR registers are indexed 0-7; bits within each register are 0-7.")
print("Enter -1 to print all registers, or all bits.") print("Enter -1 to print all registers, or all bits.")
steps = prompt_int("How many steps do you want to run? (1100): ", 1, 100) steps = prompt_int("How many steps do you want to run? (1-100): ", 1, 100)
reg = prompt_int("Which R register do you want to inspect? (-1 or 07): ", -1, 7) reg = prompt_int("Which R register do you want to inspect? (-1 or 0-7): ", -1, 7)
bit = prompt_int("Which bit of that register? (-1 or 07): ", -1, 7) bit = prompt_int("Which bit of that register? (-1 or 0-7): ", -1, 7)
print("-" * 50) print("-" * 50)
@@ -42,12 +42,12 @@ def run_classic_cli():
print("Done.") print("Done.")
def run_advanced_cli(): def run_advanced_cli():
print("\nR registers are indexed 07; bits within each register are 07.") print("\nR registers are indexed 0-7; bits within each register are 0-7.")
print("x and r registers are indexed 04; bits within each register are 07.") print("x and r registers are indexed 0-4; bits within each register are 0-7.")
steps = prompt_int("How many steps do you want to run? (1100): ", 1, 100) steps = prompt_int("How many steps do you want to run? (1-100): ", 1, 100)
reg = prompt_int("Which R register do you want to inspect? (-1 or 07): ", -1, 7) reg = prompt_int("Which R register do you want to inspect? (-1 or 0-7): ", -1, 7)
bit = prompt_int("Which bit of that register? (-1 or 07): ", -1, 7) bit = prompt_int("Which bit of that register? (-1 or 0-7): ", -1, 7)
raw = input("Bits to set to 0 (space-separated): ").strip() raw = input("Bits to set to 0 (space-separated): ").strip()
zero_bits = raw.split() if raw else [] zero_bits = raw.split() if raw else []
@@ -94,12 +94,12 @@ def run_exhaustive_cli():
family = prompt_choice("Your choice (1, 2, 3 or 4): ", {1, 2, 3, 4}) family = prompt_choice("Your choice (1, 2, 3 or 4): ", {1, 2, 3, 4})
print("\nR registers are indexed 07; bits within each register are 07.") 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.") print("Enter -1 to print all bits in the chosen register.")
steps = prompt_int("How many steps? (1100): ", 1, 100) steps = prompt_int("How many steps? (1-100): ", 1, 100)
target_reg = prompt_int("Target register (07): ", 0, 7) target_reg = prompt_int("Target register (0-7): ", 0, 7)
target_bit = prompt_int("Target bit (-1 or 07): ", -1, 7) target_bit = prompt_int("Target bit (-1 or 0-7): ", -1, 7)
print("-" * 50) print("-" * 50)
@@ -117,13 +117,13 @@ def run_exhaustive_cli():
def run_variable_xor_cli(): def run_variable_xor_cli():
print("\nR registers are indexed 07; bits within each register are 07.") print("\nR registers are indexed 0-7; bits within each register are 0-7.")
print("Enter the bit positions to XOR, e.g. `0 1`.") print("Enter the bit positions to XOR, e.g. `0 1`.")
steps = prompt_int("How many steps? (1100): ", 1, 100) steps = prompt_int("How many steps? (1-100): ", 1, 100)
target_reg = prompt_int("Target register (07): ", 0, 7) target_reg = prompt_int("Target register (0-7): ", 0, 7)
bits_to_xor = prompt_list( bits_to_xor = prompt_list(
"Bits to XOR (07, separated by spaces, ranges with '-'): ", "Bits to XOR (0-7, separated by spaces, ranges with '-'): ",
item_name="bit", item_name="bit",
min_value=0, min_value=0,
max_value=7, max_value=7,
@@ -136,12 +136,12 @@ def run_variable_xor_cli():
print("Done.") print("Done.")
def run_exhaustive_xor_cli(): def run_exhaustive_xor_cli():
print("\nR registers are indexed 07; bits within each register are 07.") print("\nR registers are indexed 0-7; bits within each register are 0-7.")
print("This mode searches all XOR combinations of a given size.") print("This mode searches all XOR combinations of a given size.")
steps = prompt_int("How many steps? (1100): ", 1, 100) steps = prompt_int("How many steps? (1-100): ", 1, 100)
target_reg = prompt_int("Target register (07): ", 0, 7) target_reg = prompt_int("Target register (0-7): ", 0, 7)
xor_size = prompt_int("Number of bits to XOR (28): ", 2, 8) xor_size = prompt_int("Number of bits to XOR (2-8): ", 2, 8)
print("-" * 50) print("-" * 50)
@@ -154,9 +154,9 @@ def run_exhaustive_xor_cli():
def run_cube_attack_cli(model = None): def run_cube_attack_cli(model = None):
print("\nCube attack search on TEA3 model to search for low-degree superpolys.") print("\nCube attack search on TEA3 model to search for low-degree superpolys.")
rounds = prompt_int("How many rounds? (1100): ", 1, 100) rounds = prompt_int("How many rounds? (1-100): ", 1, 100)
target_reg = prompt_int("Target R register (07): ", 0, 7) target_reg = prompt_int("Target R register (0-7): ", 0, 7)
target_bit = prompt_int("Target bit of that register (07): ", 0, 7) target_bit = prompt_int("Target bit of that register (0-7): ", 0, 7)
raw = input("Bits to set to 0: ").strip() raw = input("Bits to set to 0: ").strip()
fixed_zero_bits = raw.split() if raw else [] fixed_zero_bits = raw.split() if raw else []
@@ -164,7 +164,7 @@ def run_cube_attack_cli(model = None):
raw = input("Bits to set to 1: ").strip() raw = input("Bits to set to 1: ").strip()
fixed_one_bits = raw.split() if raw else [] fixed_one_bits = raw.split() if raw else []
cube_size = prompt_int("Cube size (164): ", 1, 64) cube_size = prompt_int("Cube size (1-64): ", 1, 64)
print("\nSearch strategy:") print("\nSearch strategy:")
print(" 1) Exhaustive") print(" 1) Exhaustive")
@@ -174,13 +174,13 @@ def run_cube_attack_cli(model = None):
if strategy == 1: if strategy == 1:
mode = "exhaustive" mode = "exhaustive"
samples = 0 samples = 0
limit = prompt_int("How many results to keep? (1100): ", 1, 100) limit = prompt_int("How many results to keep? (1-100): ", 1, 100)
else: else:
mode = "random" mode = "random"
samples = prompt_int("How many random cubes to test? (1200000): ", 1, 200000) samples = prompt_int("How many random cubes to test? (1-200000): ", 1, 200000)
limit = prompt_int("How many results to keep? (1100): ", 1, 100) limit = prompt_int("How many results to keep? (1-100): ", 1, 100)
max_degree = prompt_int("Maximum accepted degree (05): ", 0, 5) max_degree = prompt_int("Maximum accepted degree (0-5): ", 0, 5)
print("-" * 50) print("-" * 50)
run_cube_attack( run_cube_attack(
@@ -204,9 +204,9 @@ def run_cube_attack_cli(model = None):
def run_cube_attack_oracle_cli(): def run_cube_attack_oracle_cli():
print("\nBlack-box cube attack search on TEA3.") print("\nBlack-box cube attack search on TEA3.")
print("This mode varies frame-number bits and queries the cipher directly.") print("This mode varies frame-number bits and queries the cipher directly.")
print("Frame-number bits are indexed 031, with 0 = least significant bit.") print("Frame-number bits are indexed 0-31, with 0 = least significant bit.")
base_frame_number = prompt_int("Base frame number (04294967295): ", 0, 0xFFFFFFFF) base_frame_number = prompt_int("Base frame number (0-4294967295): ", 0, 0xFFFFFFFF)
raw = input("Frame bits to set to 0 (space-separated): ").strip() raw = input("Frame bits to set to 0 (space-separated): ").strip()
fixed_zero_bits = raw.split() if raw else [] fixed_zero_bits = raw.split() if raw else []
@@ -214,10 +214,10 @@ def run_cube_attack_oracle_cli():
raw = input("Frame bits to set to 1 (space-separated): ").strip() raw = input("Frame bits to set to 1 (space-separated): ").strip()
fixed_one_bits = raw.split() if raw else [] fixed_one_bits = raw.split() if raw else []
output_byte = prompt_int("Output keystream byte (063): ", 0, 63) output_byte = prompt_int("Output keystream byte (0-63): ", 0, 63)
output_bit = prompt_int("Output bit within that byte (07): ", 0, 7) output_bit = prompt_int("Output bit within that byte (0-7): ", 0, 7)
cube_size = prompt_int("Cube size (132): ", 1, 32) cube_size = prompt_int("Cube size (1-32): ", 1, 32)
print("\nSearch strategy:") print("\nSearch strategy:")
print(" 1) Exhaustive") print(" 1) Exhaustive")
@@ -227,11 +227,11 @@ def run_cube_attack_oracle_cli():
if strategy == 1: if strategy == 1:
mode = "exhaustive" mode = "exhaustive"
samples = 0 samples = 0
limit = prompt_int("How many results to keep? (1100): ", 1, 100) limit = prompt_int("How many results to keep? (1-100): ", 1, 100)
else: else:
mode = "random" mode = "random"
samples = prompt_int("How many random cubes to test? (1200000): ", 1, 200000) samples = prompt_int("How many random cubes to test? (1-200000): ", 1, 200000)
limit = prompt_int("How many results to keep? (1100): ", 1, 100) limit = prompt_int("How many results to keep? (1-100): ", 1, 100)
raw = input( raw = input(
"Enter 10 key bytes in hex or decimal, separated by spaces " "Enter 10 key bytes in hex or decimal, separated by spaces "
+2 -2
View File
@@ -10,9 +10,9 @@ def run_precompute_cli():
build a model, optionally fix bits, run n steps (with or without abstraction), and save the model to a file. build a model, optionally fix bits, run n steps (with or without abstraction), and save the model to a file.
""" """
print("\nPrecompute and save model") print("\nPrecompute and save model")
print("R registers 07; x,r registers 04; bits 07.") print("R registers 0-7; x,r registers 0-4; bits 0-7.")
steps = prompt_int("How many steps to precompute? (1100): ", 1, 100) steps = prompt_int("How many steps to precompute? (1-100): ", 1, 100)
raw0 = input("Bits to set to 0: ").strip() raw0 = input("Bits to set to 0: ").strip()
zero_bits = raw0.split() if raw0 else [] zero_bits = raw0.split() if raw0 else []
+2 -2
View File
@@ -54,10 +54,10 @@ def set_int_bits(value: int, bit_names, bit_value: int) -> int:
if not name: if not name:
continue continue
if not name.isdigit(): if not name.isdigit():
raise ValueError(f"Invalid bit index '{name}'. Expected integers 031.") raise ValueError(f"Invalid bit index '{name}'. Expected integers 0-31.")
idx = int(name) idx = int(name)
if idx < 0 or idx > 31: if idx < 0 or idx > 31:
raise ValueError(f"Bit index out of range: {idx}. Expected 031.") raise ValueError(f"Bit index out of range: {idx}. Expected 0-31.")
if bit_value == 0: if bit_value == 0:
x &= ~(1 << idx) x &= ~(1 << idx)
else: else: