Skip to content

Commit 49ab18e

Browse files
committed
Merge branch 'dev' for release 1.2.5
2 parents 52310a4 + 8451a36 commit 49ab18e

File tree

8 files changed

+206
-187
lines changed

8 files changed

+206
-187
lines changed

Cargo.lock

Lines changed: 106 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "worgen_x"
3-
version = "1.2.4"
3+
version = "1.2.5"
44
edition = "2024"
55
authors = ["Xen0rInspire"]
66
license = "GNU General Public License v3.0"
@@ -15,12 +15,12 @@ cli = ["serde_json", "clap"]
1515
gui = []
1616

1717
[dependencies]
18-
rand = { version = "0.9.1", features = ["thread_rng"], default-features = false }
19-
thiserror = { version = "2.0.12", default-features = false }
18+
rand = { version = "0.9.2", features = ["thread_rng"], default-features = false }
19+
thiserror = { version = "2.0.17", default-features = false }
2020
num_cpus = { version = "1.17.0", default-features = false }
21-
serde_json = { version = "1.0.140", optional = true, features = ["std"], default-features = false }
22-
indicatif = { version = "0.17.11", default-features = false }
23-
clap = { version = "4.5.40", optional = true, features = ["std"], default-features = false }
21+
serde_json = { version = "1.0.145", optional = true, features = ["std"], default-features = false }
22+
indicatif = { version = "0.18.0", default-features = false }
23+
clap = { version = "4.5.48", optional = true, features = ["std"], default-features = false }
2424
hex = { version = "0.4.3", features = ["alloc"], default-features = false }
2525
md-5 = { version = "0.10.6", default-features = false }
2626
sha-1 = { version = "0.10.1", default-features = false }

src/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn load_cpu_benchmark(nb_of_threads: usize) -> Result<u64, WorgenXError> {
6565
for _ in 0..nb_of_threads {
6666
let shared_signal_rst: Arc<AtomicBool> = Arc::clone(&shared_signal);
6767
threads.push(thread::spawn(move || {
68-
run_stress_test(&shared_signal_rst).unwrap_or_else(|e| println!("{}", e));
68+
run_stress_test(&shared_signal_rst).unwrap_or_else(|e| println!("{e}"));
6969
}));
7070
}
7171

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828

2929
#[cfg(feature = "cli")]
3030
if let Err(e) = mode::cli::run() {
31-
eprintln!("{}", e);
31+
eprintln!("{e}");
3232
std::process::exit(1);
3333
}
3434

src/mode/cli.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct BenchmarkOptions {
4646
///
4747
/// Command struct containing the different features of WorgenX.
4848
///
49+
#[allow(clippy::too_many_lines)]
4950
fn build_command_context() -> Command {
5051
let default_threads: &'static str = Box::leak(num_cpus::get().to_string().into_boxed_str()); // Ensure a static reference to the number of logical cores of the CPU
5152
let wordlist_command: Command = Command::new("wordlist")
@@ -274,7 +275,7 @@ fn run_passwd(sub_matches: &ArgMatches) -> Result<(), WorgenXError> {
274275
};
275276

276277
if !password_generation_parameters.no_display {
277-
println!("{}", all_passwords);
278+
println!("{all_passwords}");
278279
}
279280

280281
if !password_generation_parameters.output_file.is_empty() {
@@ -375,7 +376,13 @@ fn run_wordlist(sub_matches: &ArgMatches) -> Result<(), WorgenXError> {
375376

376377
let wordlist_config: WordlistConfig = wordlist::build_wordlist_config(&wordlist_generation_parameters.wordlist_values);
377378
let nb_of_passwords: u64 = wordlist_config.dict.len().pow(wordlist_config.mask_indexes.len() as u32) as u64;
378-
println!("Estimated size of the wordlist: {}", system::get_estimated_size(nb_of_passwords, wordlist_config.formated_mask.len() as u64));
379+
let len_of_string: u64 = if wordlist_config.hash.is_empty() {
380+
wordlist_config.formated_mask.len() as u64
381+
} else {
382+
system::get_size_of_hash(&wordlist_config.hash) as u64
383+
};
384+
385+
println!("Estimated size of the wordlist: {}", system::get_estimated_size(nb_of_passwords, len_of_string));
379386
println!("Wordlist generation in progress...");
380387

381388
wordlist::wordlist_generation_scheduler(
@@ -454,7 +461,7 @@ fn run_benchmark(sub_matches: &ArgMatches) -> Result<(), WorgenXError> {
454461
let benchmark_parameters: BenchmarkOptions = allocate_benchmark_config_cli(sub_matches);
455462
let result: u64 = benchmark::load_cpu_benchmark(benchmark_parameters.threads)?;
456463

457-
println!("Your CPU has generated {} passwords in 1 minute", result);
464+
println!("Your CPU has generated {result} passwords in 1 minute");
458465
Ok(())
459466
}
460467

src/mode/gui.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn main_passwd_generation() {
104104
while let Err(e) =
105105
system::save_passwd_to_file(&Arc::clone(&shared_file), &passwords.join("\n"))
106106
{
107-
println!("\n{}", e);
107+
println!("\n{e}");
108108
println!("Do you want to try again ? (y/n)");
109109
let choice: String = system::get_user_choice_yn();
110110
if choice.eq("n") {
@@ -192,10 +192,13 @@ fn main_wordlist_generation() {
192192
.len()
193193
.pow(wordlist_config.mask_indexes.len() as u32)
194194
as u64;
195-
println!(
196-
"Estimated size of the wordlist: {}",
197-
system::get_estimated_size(nb_of_passwords, wordlist_config.formated_mask.len() as u64)
198-
);
195+
196+
let len_of_string: u64 = if wordlist_config.hash.is_empty() {
197+
wordlist_config.formated_mask.len() as u64
198+
} else {
199+
system::get_size_of_hash(&wordlist_config.hash) as u64
200+
};
201+
println!("Estimated size of the wordlist: {}", system::get_estimated_size(nb_of_passwords, len_of_string));
199202
println!("Do you want to continue ? (y/n)");
200203
if system::get_user_choice_yn().eq("n") {
201204
return;
@@ -220,11 +223,11 @@ fn main_wordlist_generation() {
220223
&filename,
221224
false,
222225
) {
223-
println!("{}", e);
226+
println!("{e}");
224227
return;
225228
}
226229

227-
println!("The wordlist has been saved in the file : {}", filename);
230+
println!("The wordlist has been saved in the file : {filename}");
228231
println!("\nDo you want to generate another wordlist ? (y/n)");
229232
again = system::get_user_choice_yn();
230233
}
@@ -319,8 +322,8 @@ fn main_benchmark() {
319322
println!("The benchmark will start in 5 seconds...");
320323
thread::sleep(std::time::Duration::from_secs(5));
321324
match benchmark::load_cpu_benchmark(num_cpus::get()) {
322-
Ok(nb_of_passwords) => println!("Your CPU has generated {} passwords in 1 minute", nb_of_passwords),
323-
Err(e) => println!("{}", e),
325+
Ok(nb_of_passwords) => println!("Your CPU has generated {nb_of_passwords} passwords in 1 minute"),
326+
Err(e) => println!("{e}"),
324327
}
325328

326329
println!("\nDo you want to run a new benchmark ? (y/n)");
@@ -350,20 +353,20 @@ pub fn saving_procedure(target: &str) -> Result<(File, String), SystemError> {
350353

351354
let filename: String = env::var(target::HOME_ENV_VAR).map_or_else(|_| {
352355
println!("Unable to get the home directory, the file will be saved in the current directory\n");
353-
format!("./{}", filename)
356+
format!("./{filename}")
354357
}, |home_path| {
355-
let parent_folder: String = format!("{}{}", home_path, target);
358+
let parent_folder: String = format!("{home_path}{target}");
356359
let parent_folder_created: String = match system::create_folder_if_not_exists(
357360
&parent_folder,
358361
) {
359-
Ok(()) => format!("{}{}", home_path, target),
362+
Ok(()) => format!("{home_path}{target}"),
360363
Err(e) => {
361-
println!("{}", e);
364+
println!("{e}");
362365
println!("Unable to create the folder, the file will be saved in the current directory");
363-
format!("./{}", filename)
366+
format!("./{filename}")
364367
}
365368
};
366-
format!("{}{}", parent_folder_created, filename)
369+
format!("{parent_folder_created}{filename}")
367370
});
368371

369372
let file: File = match OpenOptions::new()
@@ -374,7 +377,7 @@ pub fn saving_procedure(target: &str) -> Result<(File, String), SystemError> {
374377
{
375378
Ok(file) => file,
376379
Err(e) => {
377-
println!("{}", e);
380+
println!("{e}");
378381
return Err(SystemError::UnableToCreateFile(filename, e.to_string()));
379382
}
380383
};

src/system.rs

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use sha1::Sha1;
1010
use sha2::{Sha224, Sha256, Sha384, Sha512};
1111
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
1212
use std::{
13+
fmt::Write as WriteStr,
1314
fs::File,
1415
io::Write,
1516
path::Path,
@@ -105,7 +106,7 @@ where
105106
println!("Please enter a valid number greater than 0");
106107
}
107108
}
108-
Err(e) => println!("Please enter a valid number greater than 0, {}", e),
109+
Err(e) => println!("Please enter a valid number greater than 0, {e}"),
109110
}
110111
}
111112

@@ -283,7 +284,7 @@ pub fn save_passwd_to_file(file: &Arc<Mutex<File>>, passwords: &str) -> Result<(
283284
))
284285
})?;
285286

286-
file.write_all(format!("{}\n", passwords).as_bytes())
287+
file.write_all(format!("{passwords}\n").as_bytes())
287288
.map_err(|_| {
288289
WorgenXError::SystemError(SystemError::UnableToWriteToFile(
289290
"output file".to_string(),
@@ -331,20 +332,20 @@ pub fn get_estimated_size(nb_of_passwords: u64, length: u64) -> String {
331332
let size: u64 = nb_of_passwords * (length + 1); // +1 for the newline character
332333
let mut size_str: String = String::new();
333334
if size < 1024 {
334-
size_str.push_str(&size.to_string());
335-
size_str.push_str(" bytes");
335+
write!(size_str, "{size}").unwrap_or_default();
336+
write!(size_str, " bytes").unwrap_or_default();
336337
} else if size < 1048576 {
337-
size_str.push_str(&format!("{:.2}", size as f64 / 1024.0));
338-
size_str.push_str(" KB");
338+
write!(size_str, "{:.2}", size as f64 / 1024.0).unwrap_or_default();
339+
write!(size_str, " KB").unwrap_or_default();
339340
} else if size < 1073741824 {
340-
size_str.push_str(&format!("{:.2}", size as f64 / 1048576.0));
341-
size_str.push_str(" MB");
341+
write!(size_str, "{:.2}", size as f64 / 1048576.0).unwrap_or_default();
342+
write!(size_str, " MB").unwrap_or_default();
342343
} else if size < 1099511627776 {
343-
size_str.push_str(&format!("{:.2}", size as f64 / 1073741824.0));
344-
size_str.push_str(" GB");
344+
write!(size_str, "{:.2}", size as f64 / 1073741824.0).unwrap_or_default();
345+
write!(size_str, " GB").unwrap_or_default();
345346
} else {
346-
size_str.push_str(&format!("{:.2}", size as f64 / 1099511627776.0));
347-
size_str.push_str(" TB");
347+
write!(size_str, "{:.2}", size as f64 / 1099511627776.0).unwrap_or_default();
348+
write!(size_str, " TB").unwrap_or_default();
348349
}
349350
size_str
350351
}
@@ -399,6 +400,36 @@ fn hash_with_digest<D: Digest>(mut hasher: D, password: &str) -> String {
399400
hex::encode(result)
400401
}
401402

403+
/// This function returns the size of the hash in bytes for a given hash algorithm.
404+
/// It is used to determine the size of the hash in bytes.
405+
///
406+
/// # Arguments
407+
///
408+
/// * `hash` - The hash algorithm to check.
409+
///
410+
/// # Returns
411+
///
412+
/// The size of the hash in bytes. If the hash algorithm is not supported, it returns 0.
413+
///
414+
pub fn get_size_of_hash(hash: &str) -> usize {
415+
match hash {
416+
"md5" => 32,
417+
"sha1" => 40,
418+
"sha224" => 56,
419+
"sha256" => 64,
420+
"sha384" => 96,
421+
"sha512" => 128,
422+
"sha3-224" => 56,
423+
"sha3-256" => 64,
424+
"sha3-384" => 96,
425+
"sha3-512" => 128,
426+
"blake2b-512" => 128,
427+
"blake2s-256" => 64,
428+
"whirlpool" => 128,
429+
_ => 0, // Unsupported hash algorithm.
430+
}
431+
}
432+
402433
#[cfg(test)]
403434
mod tests {
404435
use super::*;
@@ -509,4 +540,22 @@ mod tests {
509540
assert_eq!(manage_hash(password, "whirlpool").unwrap(), "74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae");
510541
assert!(manage_hash(password, "sha999").is_err());
511542
}
543+
544+
#[test]
545+
fn test_get_size_of_hash() {
546+
assert_eq!(get_size_of_hash("md5"), 32);
547+
assert_eq!(get_size_of_hash("sha1"), 40);
548+
assert_eq!(get_size_of_hash("sha224"), 56);
549+
assert_eq!(get_size_of_hash("sha256"), 64);
550+
assert_eq!(get_size_of_hash("sha384"), 96);
551+
assert_eq!(get_size_of_hash("sha512"), 128);
552+
assert_eq!(get_size_of_hash("sha3-224"), 56);
553+
assert_eq!(get_size_of_hash("sha3-256"), 64);
554+
assert_eq!(get_size_of_hash("sha3-384"), 96);
555+
assert_eq!(get_size_of_hash("sha3-512"), 128);
556+
assert_eq!(get_size_of_hash("blake2b-512"), 128);
557+
assert_eq!(get_size_of_hash("blake2s-256"), 64);
558+
assert_eq!(get_size_of_hash("whirlpool"), 128);
559+
assert_eq!(get_size_of_hash("sha999"), 0); // Unsupported hash algorithm
560+
}
512561
}

src/wordlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn wordlist_generation_scheduler(
191191
return Err(err.clone());
192192
}
193193

194-
return Err(WorgenXError::SystemError(SystemError::ThreadError(format!("{:?}", e))));
194+
return Err(WorgenXError::SystemError(SystemError::ThreadError(format!("{e:?}"))));
195195
}
196196

197197
println!("\nWordlist generated in {}", system::get_elapsed_time(start));
@@ -340,7 +340,7 @@ fn generate_wordlist_part(
340340
}
341341

342342
if !found {
343-
line.push(formated_mask[i])
343+
line.push(formated_mask[i]);
344344
}
345345
});
346346
for idx in (0..dict_indexes.len()).rev() {

0 commit comments

Comments
 (0)