From a2d820b4e5d63ce9d292732cf629627eef377e47 Mon Sep 17 00:00:00 2001 From: Olivia Brooks <109807080+Cutieguwu@users.noreply.github.com> Date: Sun, 23 Nov 2025 22:40:25 -0500 Subject: [PATCH] Cleanups; Attempting improvements and optimizations. --- Cargo.lock | 141 ++++------------------------------------------------ Cargo.toml | 3 +- src/main.rs | 56 +++++++++------------ 3 files changed, 34 insertions(+), 166 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e132881..633f366 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,12 +11,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - [[package]] name = "crypto-common" version = "0.1.7" @@ -48,22 +42,10 @@ dependencies = [ ] [[package]] -name = "getrandom" -version = "0.3.4" +name = "hermit-abi" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "hex-literal" @@ -90,83 +72,19 @@ dependencies = [ name = "md_undo" version = "0.1.0" dependencies = [ - "hex", "hex-literal", "md2", - "rand", + "num_cpus", ] [[package]] -name = "ppv-lite86" -version = "0.2.21" +name = "num_cpus" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "r-efi" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" - -[[package]] -name = "rand" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" -dependencies = [ - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" -dependencies = [ - "getrandom", -] - -[[package]] -name = "syn" -version = "2.0.110" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "hermit-abi", + "libc", ] [[package]] @@ -175,49 +93,8 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" -[[package]] -name = "unicode-ident" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" - [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasip2" -version = "1.0.1+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wit-bindgen" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" - -[[package]] -name = "zerocopy" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43fa6694ed34d6e57407afbccdeecfa268c470a7d2a5b0cf49ce9fcc345afb90" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c640b22cd9817fae95be82f0d2f90b11f7605f6c319d16705c459b27ac2cbc26" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/Cargo.toml b/Cargo.toml index a4c7028..53b0ecc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] -hex = "0.4.3" hex-literal = "1.1.0" md2 = "0.10.2" -rand = "0.9.2" +num_cpus = "1.17.0" diff --git a/src/main.rs b/src/main.rs index c94b50d..36a53b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,66 +1,58 @@ -use std::thread; +use std::{sync::LazyLock, thread}; use hex_literal; use md2::{Digest, Md2}; +use num_cpus; + +static MAX_THREADS: LazyLock = LazyLock::new(|| num_cpus::get()); -const CHAR_SET: &[u8] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ&.<(+|-!$*);/,%_>?:#'0=\"@~".as_bytes(); -const MAX_LEN: usize = CHAR_SET.len(); const TARGET: [u8; 16] = hex_literal::hex!("e809236d4b94e54174e666cf3b1f53ce"); const KNOWN: &str = "CYBERSCI(PUNCH?C4RD?1S?7H3?FL4SH?ST0RAGE?OF?"; const KNOWN_TRAIL: &str = ")"; fn main() { - let mut hasher = Md2::new(); - hasher.update(KNOWN); - let mut handles = vec![]; - for idx in 0..MAX_LEN { + let fraction = u32::MAX as usize / *MAX_THREADS; + for idx in 0..*MAX_THREADS { + println!("Spawned worker thread {}", idx); handles.push(thread::spawn(move || { - brute(CHAR_SET[idx.clone()]); + // Pretend you don't see this. + // Also, who would have u32::MAX + 1 threads anyway? + brute((fraction * idx) as u32, fraction as u32); })); } for h in handles { - h.join().unwrap(); + h.join().unwrap(); // Yes, I'm calling unwrap on Result<_>. No, I don't work at Cloudflare. } } -fn brute(start_val: u8) { +fn brute(start_val: u32, delta: u32) { + println!("{}", start_val); + // Init MD2 hasher. let mut hasher = Md2::new(); hasher.update(KNOWN); let mut result = hasher.finalize_reset(); - let mut a: usize = 0; - let mut b: usize = 0; - let mut c: usize = 0; - + // Brute force given range. + let mut idx: u32 = start_val; let mut guess = String::new(); - while result[..] != TARGET { - if a == (MAX_LEN - 1) { - a = 0; - b += 1; - } else { - a += 1; - } + while (result[..] != TARGET) && (idx != start_val + delta) { + idx += 1; - if b == MAX_LEN { - b = 0; - c += 1; - } - - if c == MAX_LEN { - return (); - } + let seq: [u8; 4] = idx.clone().to_ne_bytes(); + println!("{:?}", &seq); guess = format!( "{}{}{}{}{}{}", - KNOWN, &start_val, CHAR_SET[c], CHAR_SET[b], CHAR_SET[a], KNOWN_TRAIL + KNOWN, seq[0] as char, seq[1] as char, seq[2] as char, seq[3] as char, KNOWN_TRAIL ); hasher.update(&guess); result = hasher.finalize_reset(); } - println!("{}", guess); + if result[..] == TARGET { + println!("{}", guess); + } }