clap
This commit is contained in:
+45
-6
@@ -2,25 +2,63 @@ mod lfsr;
|
||||
mod period;
|
||||
mod tea3;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use lfsr::Lfsr;
|
||||
use period::{longest_period_parallel, period_bruteforce, period_floyd, period_paper};
|
||||
use period::{longest_period_parallel, period_paper};
|
||||
use tea3::Tea3;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "tea3-tools")]
|
||||
#[command(about = "LFSR / TEA-3 test utilities", long_about = None)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Test the LFSR
|
||||
Lfsr,
|
||||
|
||||
/// Test TEA-3 keystream and encryption/decryption
|
||||
Tea3,
|
||||
|
||||
/// Test for periods in TEA-3 register h
|
||||
Periods,
|
||||
|
||||
/// Search for greatest period in TEA-3 register h
|
||||
GreatestPeriod,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Commands::Lfsr => test_lfsr(),
|
||||
Commands::Tea3 => test_tea3(),
|
||||
Commands::Periods => test_periods(),
|
||||
Commands::GreatestPeriod => find_greatest_period(),
|
||||
}
|
||||
}
|
||||
|
||||
fn test_lfsr() {
|
||||
let mut lfsr = Lfsr::new(4, vec![0, 3], vec![0x12, 0x34, 0x56, 0x78]);
|
||||
|
||||
for _ in 0..16 {
|
||||
let byte = lfsr.next();
|
||||
println!("{:02x} | state: {:?}", byte, lfsr.state());
|
||||
}
|
||||
}
|
||||
|
||||
fn test_tea3() {
|
||||
let key = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let state = vec![0; 8];
|
||||
|
||||
let mut cipher = Tea3::new(key.clone(), state.clone());
|
||||
cipher.init();
|
||||
|
||||
println!("\nKeystream:");
|
||||
println!("Keystream:");
|
||||
for _ in 0..10 {
|
||||
let byte = cipher.next_byte();
|
||||
println!("{:#04x}", byte);
|
||||
@@ -48,9 +86,11 @@ fn main() {
|
||||
.collect();
|
||||
|
||||
println!("Decrypted : {:?}", decrypted);
|
||||
}
|
||||
|
||||
fn test_periods() {
|
||||
println!(
|
||||
"\nPaper period p0: {}",
|
||||
"Paper period p0: {}",
|
||||
period_paper(vec![0xc2, 0xc2, 0xc2, 0xc2, 0xc2])
|
||||
);
|
||||
println!(
|
||||
@@ -61,10 +101,9 @@ fn main() {
|
||||
"Paper period p14: {}",
|
||||
period_paper(vec![0xe3, 0x61, 0x62, 0x00, 0x00])
|
||||
);
|
||||
}
|
||||
|
||||
// println!("\nPaper period p20: {}", period_paper(vec![0x7a, 0x02, 0x00, 0x00, 0x00]));
|
||||
// println!("\nPaper period p27: {}", period_paper(vec![0x00, 0x00, 0x00, 0x00, 0x00]));
|
||||
|
||||
fn find_greatest_period() {
|
||||
let (p, seed) = longest_period_parallel();
|
||||
println!("\nLongest period: {}", p);
|
||||
println!("Seed: {:02x?}", seed);
|
||||
|
||||
Reference in New Issue
Block a user