This commit is contained in:
2026-04-07 16:29:28 +02:00
parent 3b11af13d0
commit 8b79c359ec
3 changed files with 224 additions and 7 deletions

179
Cargo.lock generated
View File

@@ -1,6 +1,102 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 4
[[package]]
name = "anstream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]
name = "anstyle-parse"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "clap"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
[[package]]
name = "colorchoice"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]] [[package]]
name = "crossbeam-deque" name = "crossbeam-deque"
@@ -33,6 +129,42 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
dependencies = [
"proc-macro2",
]
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.11.0" version = "1.11.0"
@@ -53,9 +185,54 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "tea-3" name = "tea-3"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap",
"rayon", "rayon",
] ]
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]

View File

@@ -6,4 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
clap = { version = "4.6.0", features = ["derive"] }
rayon = "1.11.0" rayon = "1.11.0"

View File

@@ -2,25 +2,63 @@ mod lfsr;
mod period; mod period;
mod tea3; mod tea3;
use clap::{Parser, Subcommand};
use lfsr::Lfsr; use lfsr::Lfsr;
use period::{longest_period_parallel, period_bruteforce, period_floyd, period_paper}; use period::{longest_period_parallel, period_paper};
use tea3::Tea3; 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() { 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]); let mut lfsr = Lfsr::new(4, vec![0, 3], vec![0x12, 0x34, 0x56, 0x78]);
for _ in 0..16 { for _ in 0..16 {
let byte = lfsr.next(); let byte = lfsr.next();
println!("{:02x} | state: {:?}", byte, lfsr.state()); println!("{:02x} | state: {:?}", byte, lfsr.state());
} }
}
fn test_tea3() {
let key = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let key = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let state = vec![0; 8]; let state = vec![0; 8];
let mut cipher = Tea3::new(key.clone(), state.clone()); let mut cipher = Tea3::new(key.clone(), state.clone());
cipher.init(); cipher.init();
println!("\nKeystream:"); println!("Keystream:");
for _ in 0..10 { for _ in 0..10 {
let byte = cipher.next_byte(); let byte = cipher.next_byte();
println!("{:#04x}", byte); println!("{:#04x}", byte);
@@ -48,9 +86,11 @@ fn main() {
.collect(); .collect();
println!("Decrypted : {:?}", decrypted); println!("Decrypted : {:?}", decrypted);
}
fn test_periods() {
println!( println!(
"\nPaper period p0: {}", "Paper period p0: {}",
period_paper(vec![0xc2, 0xc2, 0xc2, 0xc2, 0xc2]) period_paper(vec![0xc2, 0xc2, 0xc2, 0xc2, 0xc2])
); );
println!( println!(
@@ -61,10 +101,9 @@ fn main() {
"Paper period p14: {}", "Paper period p14: {}",
period_paper(vec![0xe3, 0x61, 0x62, 0x00, 0x00]) period_paper(vec![0xe3, 0x61, 0x62, 0x00, 0x00])
); );
}
// println!("\nPaper period p20: {}", period_paper(vec![0x7a, 0x02, 0x00, 0x00, 0x00])); fn find_greatest_period() {
// println!("\nPaper period p27: {}", period_paper(vec![0x00, 0x00, 0x00, 0x00, 0x00]));
let (p, seed) = longest_period_parallel(); let (p, seed) = longest_period_parallel();
println!("\nLongest period: {}", p); println!("\nLongest period: {}", p);
println!("Seed: {:02x?}", seed); println!("Seed: {:02x?}", seed);