Cleanups; Attempting improvements and optimizations.

This commit is contained in:
Olivia Brooks
2025-11-23 22:40:25 -05:00
parent faad5dbcf2
commit a2d820b4e5
3 changed files with 34 additions and 166 deletions

View File

@@ -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<usize> = 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);
}
}