aes-project/src/main.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

2024-04-26 18:47:30 +02:00
mod aes;
2024-04-28 14:43:12 +02:00
mod square;
use crate::aes::Aes;
2024-04-12 18:52:42 +02:00
fn main() {
2024-04-26 18:47:30 +02:00
let key: [u8; 16] = [
2024-04-27 22:42:53 +02:00
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f,
0x3c,
2024-04-26 18:47:30 +02:00
];
2024-04-28 14:43:12 +02:00
let found_key: [u8; 16] = Aes::findroundkey(&key);
for &byte in &found_key {
print!("{:02x}", byte);
2024-04-26 18:47:30 +02:00
}
2024-04-27 22:42:53 +02:00
println!();
2024-04-28 14:43:12 +02:00
let found_key_origininal = Aes::reverse_key_schedule(&found_key, 4);
2024-04-27 22:42:53 +02:00
for &byte in &found_key_origininal {
print!("{:02x}", byte);
}
println!();
2024-04-28 14:43:12 +02:00
let nturn = 4;
let aescipher = Aes::new(&key, &nturn);
let mut output = [[0u8; 16]; 11];
for i in 0..11 {
for j in 0..4 {
output[i][4 * j..4 * (j + 1)].copy_from_slice(&aescipher.expanded_key[4 * i + j]);
}
}
for &key in &output {
for &byte in &key {
print!("{:02x}", byte);
}
println!();
}
2024-04-27 22:42:53 +02:00
2024-04-28 14:43:12 +02:00
println!("test");
for i in 0..11 {
for &byte in &Aes::reverse_key_schedule(&output[i], i) {
print!("{:02x}", byte);
}
println!();
println!();
}
2024-04-12 18:52:42 +02:00
}