period finder update
This commit is contained in:
@@ -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])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<u8>) -> 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user