use std::process::{Command, Stdio};
const CRUNCH_LOWERCASE: &str = "abcdefghijklmnopqrstuvwxyz";
const CRUNCH_UPPERCASE: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const CRUNCH_NUMBERS: &str = "0123456789";
const CRUNCH_SYMBOLS: &str = " @!#$%^&*()-_+=~`[]{}|:;<>,.?/\\";
#[derive(thiserror::Error, Debug)]
pub enum DecryptError {
#[error("Input/Output error: {0}")]
IoError(#[from] std::io::Error),
}
pub fn run_decrypt_wordlist_process(
handshake: &str,
bssid: &str,
essid: &str,
wordlist: &str,
) -> Result<(), DecryptError> {
let title = format!("Handshake Decryption ({essid})");
Command::new("xterm")
.stdin(Stdio::null())
.args([
"-hold",
"-T",
&title,
"-e",
"aircrack-ng",
handshake,
"-b",
bssid,
"-w",
wordlist,
])
.spawn()?;
Ok(())
}
pub fn run_decrypt_bruteforce_process(
handshake: &str,
bssid: &str,
essid: &str,
low: bool,
up: bool,
num: bool,
sym: bool,
) -> Result<(), DecryptError> {
let charset = format!(
"{}{}{}{}",
match low {
true => CRUNCH_LOWERCASE,
false => "",
},
match up {
true => CRUNCH_UPPERCASE,
false => "",
},
match num {
true => CRUNCH_NUMBERS,
false => "",
},
match sym {
true => CRUNCH_SYMBOLS,
false => "",
},
);
let title = format!("Handshake Decryption ({essid})");
let cmd = format!("crunch 8 64 '{charset}' | aircrack-ng -w - -b '{bssid}' '{handshake}'");
Command::new("xterm")
.stdin(Stdio::null())
.args(["-hold", "-T", &title, "-e", "sh", "-c", &cmd])
.spawn()?;
Ok(())
}