use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Speed {
Fast,
Medium,
Slow,
VerySlow,
}
impl Speed {
pub fn hashes_per_sec(self) -> f64 {
match self {
Speed::Fast => 30e9,
Speed::Medium => 50e6,
Speed::Slow => 400e3,
Speed::VerySlow => 1.5e3,
}
}
pub fn label(self) -> &'static str {
match self {
Speed::Fast => "fast",
Speed::Medium => "medium",
Speed::VerySlow => "very slow",
Speed::Slow => "slow",
}
}
}
pub fn speed_for(mode: u32) -> Option<Speed> {
Some(match mode {
0 | 100 | 900 | 1000 | 1400 | 1700 | 10800 | 17400 | 17800 | 6000 | 6900 => Speed::Fast,
10 | 20 | 110 | 120 | 1410 | 1420 | 101 | 111 | 10000 | 400 | 7900 | 1100 => Speed::Medium,
5500 | 5600 | 16500 | 13100 | 18200 | 7500 => Speed::Medium,
19600 | 19700 | 9200 | 1800 | 7400 | 2100 | 1600 | 500 | 15100 => Speed::Slow,
22000 | 9600 | 10500 | 10600 | 10700 | 10400 => Speed::Slow,
3200 | 9300 | 13400 | 15300 | 15900 | 11600 | 12500 | 13000 | 13600 | 9400 | 9500 => {
Speed::VerySlow
}
3000 => Speed::Fast,
_ => return None,
})
}
pub fn rockyou_time(mode: u32) -> Option<Duration> {
let rate = speed_for(mode)?.hashes_per_sec() * crate::gpu::tier().multiplier();
let secs = 14_344_391.0 / rate;
Some(Duration::from_secs_f64(secs))
}
pub fn oneliner(mode: u32) -> String {
let Some(speed) = speed_for(mode) else {
return String::new();
};
let rockyou = rockyou_time(mode)
.map(humanize)
.unwrap_or_else(|| "?".into());
format!(
"{} — rockyou ≈ {rockyou} {}",
speed.label(),
crate::gpu::tier().label()
)
}
pub fn humanize(d: Duration) -> String {
let s = d.as_secs_f64();
if s < 1.0 {
return "instant".into();
}
if s < 60.0 {
return format!("{}s", s.round() as u64);
}
if s < 3600.0 {
return format!("{}min", (s / 60.0).round() as u64);
}
if s < 86_400.0 {
return format!("{}h", (s / 3600.0).round() as u64);
}
if s < 86_400.0 * 14.0 {
return format!("{}d", (s / 86_400.0).round() as u64);
}
if s < 86_400.0 * 365.0 {
return format!("{}wk", (s / (86_400.0 * 7.0)).round() as u64);
}
"years".into()
}
pub fn advice(mode: u32) -> Option<&'static str> {
Some(match speed_for(mode)? {
Speed::Fast => {
"full wordlist + rules is trivial — go straight for rockyou --rules=OneRuleToRuleThemAll"
}
Speed::Medium => "full rockyou is fine; add --rules for +10-30% recovery",
Speed::Slow => "top-1M wordlist first, then targeted masks; full rockyou may be hours",
Speed::VerySlow => {
"high-value only — top-10k words + best64 rule. Full rockyou = days-weeks"
}
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_covered_mode_has_a_speed_class() {
for mode in [
500, 1600, 7400, 1800, 3200, 15100, 400, 7900, 10000, 101, 111, 9200, 9300, 13100,
19600, 19700, 18200, 7500, 9400, 9500, 9600, 13400, 15300, 15900, 11600, 12500, 13000,
13600, 10400, 16500, 5500, 5600, 2100, 22000, 10, 20, 110, 120, 1410, 1420, 1100, 0,
900, 1000, 100, 1400, 1700, 3000,
] {
assert!(speed_for(mode).is_some(), "no cost class for -m {mode}");
}
}
#[test]
fn bcrypt_is_hours_and_dwarfs_md5() {
let bcrypt = rockyou_time(3200).unwrap();
let md5 = rockyou_time(0).unwrap();
assert!(
md5 < bcrypt / 100_000,
"MD5 should be ≥5 orders faster than bcrypt"
);
assert!(
bcrypt > Duration::from_secs(1200),
"bcrypt on rockyou should be > 20min on any GPU tier"
);
}
#[test]
fn humanize_reads_naturally() {
assert_eq!(humanize(Duration::from_secs_f64(0.3)), "instant");
assert_eq!(humanize(Duration::from_secs(45)), "45s");
assert_eq!(humanize(Duration::from_secs(60 * 12)), "12min");
assert_eq!(humanize(Duration::from_secs(60 * 60 * 5)), "5h");
assert_eq!(humanize(Duration::from_secs(86_400 * 3)), "3d");
assert_eq!(humanize(Duration::from_secs(86_400 * 30)), "4wk");
}
#[test]
fn advice_matches_speed_class() {
assert!(advice(0).unwrap().contains("trivial")); assert!(advice(3200).unwrap().contains("high-value")); assert!(advice(9999).is_none()); }
#[test]
fn oneliner_for_bcrypt_mentions_slowness() {
let s = oneliner(3200);
assert!(s.contains("very slow"));
assert!(s.contains("rockyou"));
}
}