find key + test

This commit is contained in:
Sam Hadow 2024-04-28 15:21:16 +02:00
parent c8d65fbd27
commit 5ba752d95b
2 changed files with 17 additions and 3 deletions

View File

@ -41,4 +41,9 @@ fn main() {
println!();
println!();
}
let found = Aes::findkey(&key);
for &byte in &found {
print!("{:02x}", byte);
}
println!();
}

View File

@ -131,9 +131,10 @@ impl Aes {
}
found_key
}
// pub fn findkey(&key: &[u8; 16]) -> [u8; 16] {
//
// }
pub fn findkey(&key: &[u8; 16]) -> [u8; 16] {
let roundkey: [u8; 16] = Self::findroundkey(&key);
Self::reverse_key_schedule(&roundkey, 4)
}
}
#[cfg(test)]
@ -176,4 +177,12 @@ mod tests {
assert_eq!(Aes::reverse_key_schedule(&round_keys[i], i), key);
}
}
#[test]
fn find_key_test() {
let key: [u8; 16] = [
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf,
0x4f, 0x3c,
];
assert_eq!(key, Aes::findkey(&key));
}
}