1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::symbols::combinations_count;
use crate::transform_fns::TransformFn;
pub struct CrackParameter {
pub target: String,
pub alphabet: Box<[char]>,
pub max_length: u32,
pub min_length: u32,
pub transform_fn: TransformFn,
pub fair_mode: bool,
}
impl CrackParameter {
pub fn new(target: String,
alphabet: Box<[char]>,
max_length: u32,
min_length: u32,
transform_fn: TransformFn,
fair_mode: bool) -> CrackParameter {
CrackParameter {
target,
alphabet,
max_length,
min_length,
transform_fn,
fair_mode,
}
}
}
pub struct InternalCrackParameter {
pub target: String,
pub alphabet: Box<[char]>,
pub max_length: u32,
pub min_length: u32,
pub transform_fn: TransformFn,
pub thread_count: usize,
pub combinations_total: usize,
pub combinations_p_t: usize,
}
impl From<CrackParameter> for InternalCrackParameter {
fn from(cp: CrackParameter) -> Self {
let combinations_total = combinations_count(&cp.alphabet, cp.max_length, cp.min_length);
let thread_count = get_thread_count(cp.fair_mode);
let combinations_p_t = combinations_total / thread_count;
InternalCrackParameter {
target: cp.target,
alphabet: cp.alphabet,
max_length: cp.max_length,
min_length: cp.min_length,
transform_fn: cp.transform_fn,
thread_count,
combinations_total,
combinations_p_t,
}
}
}
fn get_thread_count(fair_mode: bool) -> usize {
let cpus = num_cpus::get();
if cpus > 1 && fair_mode {
cpus - 1
} else {
cpus
}
}