From 478141c97c32fa85630c0d7663721b80f73e9a05 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Tue, 7 Apr 2026 11:02:05 +0200 Subject: [PATCH] period finder update --- src/main.rs | 3 ++- src/period.rs | 22 +++------------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5f58c13..e275f9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,7 @@ fn main() { println!( "\nPaper period: {}", - period_paper(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + // period_paper(vec![0xc2, 0xc2, 0xc2, 0xc2, 0xc2]) + period_paper(vec![0x05, 0x58, 0x6f, 0xe1, 0xa3]) ); } diff --git a/src/period.rs b/src/period.rs index 675095f..bc4defb 100644 --- a/src/period.rs +++ b/src/period.rs @@ -140,24 +140,8 @@ fn period_h(start: Reg5) -> u64 { /// paper method, decomposition key register /// (Observations on TETRA Encryption Algorithm TEA-3) +/// key 5 bytes, (10 bytes but first 5 bytes are padding with 0) pub fn period_paper(key: Vec) -> u64 { - let start = Decomposed::from_key(&key); - - let p = period_h(start.h); - - for mult in [1u64, 2, 5, 10] { - let target = p * mult; - - let mut cur = start; - - for _ in 0..target { - cur.step(); - } - - if cur == start { - return target; - } - } - - panic!("No valid period found"); + let start = Decomposed::from_key(&[0, 0, 0, 0, 0, key[0], key[1], key[2], key[3], key[4]]); + period_h(start.h) // p }