Write better code.

This commit is contained in:
Olivia Brooks
2025-11-23 23:05:10 -05:00
parent a2d820b4e5
commit e9888e2a90

View File

@@ -1,4 +1,4 @@
use std::{sync::LazyLock, thread};
use std::{ops::Range, sync::LazyLock, thread};
use hex_literal;
use md2::{Digest, Md2};
@@ -19,7 +19,8 @@ fn main() {
handles.push(thread::spawn(move || {
// Pretend you don't see this.
// Also, who would have u32::MAX + 1 threads anyway?
brute((fraction * idx) as u32, fraction as u32);
let start = (fraction * idx) as u32;
brute(start..{ start + fraction as u32 });
}));
}
@@ -28,17 +29,17 @@ fn main() {
}
}
fn brute(start_val: u32, delta: u32) {
println!("{}", start_val);
fn brute(range: Range<u32>) {
println!("{}", range.start);
// Init MD2 hasher.
let mut hasher = Md2::new();
hasher.update(KNOWN);
let mut result = hasher.finalize_reset();
// Brute force given range.
let mut idx: u32 = start_val;
let mut idx: u32 = range.start;
let mut guess = String::new();
while (result[..] != TARGET) && (idx != start_val + delta) {
while (result[..] != TARGET) && (idx != range.end) {
idx += 1;
let seq: [u8; 4] = idx.clone().to_ne_bytes();