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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use crate::checkers::CheckerTypes;
use crate::decoders::interface::check_string_success;
use super::crack_results::CrackResult;
use super::interface::Crack;
use super::interface::Decoder;
use log::{debug, info, trace};
pub struct Base58MoneroDecoder;
impl Crack for Decoder<Base58MoneroDecoder> {
fn new() -> Decoder<Base58MoneroDecoder> {
Decoder {
name: "Base58 Monero",
description: "Base58 is a group of binary-to-text encoding schemes that represent binary data (more specifically, a sequence of 8-bit bytes) in an ASCII string format by translating the data into a radix-32 representation.",
link: "https://en.wikipedia.org/wiki/Base58",
tags: vec!["base58_monero", "base58", "monero", "cryptocurrency", "decoder", "base"],
popularity: 0.4,
phantom: std::marker::PhantomData,
}
}
fn crack(&self, text: &str, checker: &CheckerTypes) -> CrackResult {
trace!("Trying Base58_monero with text {:?}", text);
let decoded_text = decode_base58_monero_no_error_handling(text);
let mut results = CrackResult::new(self, text.to_string());
if decoded_text.is_none() {
debug!("Failed to decode base58_monero because Base58MoneroDecoder::decode_base58_monero_no_error_handling returned None");
return results;
}
let decoded_text = decoded_text.unwrap();
if !check_string_success(&decoded_text, text) {
info!(
"Failed to decode base58_monero because check_string_success returned false on string {}",
decoded_text
);
return results;
}
let checker_result = checker.check(&decoded_text);
results.unencrypted_text = Some(vec![decoded_text]);
results.update_checker(&checker_result);
results
}
fn get_tags(&self) -> &Vec<&str> {
&self.tags
}
fn get_name(&self) -> &str {
self.name
}
}
fn decode_base58_monero_no_error_handling(text: &str) -> Option<String> {
if let Ok(decoded_text) = bs58::decode(text)
.with_alphabet(bs58::Alphabet::MONERO)
.into_vec()
{
return Some(String::from_utf8_lossy(&decoded_text).to_string());
}
None
}
#[cfg(test)]
mod tests {
use super::Base58MoneroDecoder;
use crate::{
checkers::{
athena::Athena,
checker_type::{Check, Checker},
CheckerTypes,
},
decoders::interface::{Crack, Decoder},
};
fn get_athena_checker() -> CheckerTypes {
let athena_checker = Checker::<Athena>::new();
CheckerTypes::CheckAthena(athena_checker)
}
#[test]
fn successful_decoding() {
let base58_monero_decoder = Decoder::<Base58MoneroDecoder>::new();
let result = base58_monero_decoder.crack("StV1DL6CwTryKyV", &get_athena_checker());
let decoded_str = &result
.unencrypted_text
.expect("No unencrypted text for base58_monero");
assert_eq!(decoded_str[0], "hello world");
}
#[test]
fn base58_monero_decode_empty_string() {
let base58_monero_decoder = Decoder::<Base58MoneroDecoder>::new();
let result = base58_monero_decoder
.crack("", &get_athena_checker())
.unencrypted_text;
assert!(result.is_none());
}
#[test]
fn base58_monero_decode_handles_panics() {
let base58_monero_decoder = Decoder::<Base58MoneroDecoder>::new();
let result = base58_monero_decoder
.crack(
"hello my name is panicky mc panic face!",
&get_athena_checker(),
)
.unencrypted_text;
if result.is_some() {
panic!("Decode_base58_monero did not return an option with Some<t>.")
} else {
assert_eq!(true, true);
}
}
#[test]
fn base58_monero_handle_panic_if_empty_string() {
let base58_monero_decoder = Decoder::<Base58MoneroDecoder>::new();
let result = base58_monero_decoder
.crack("", &get_athena_checker())
.unencrypted_text;
if result.is_some() {
assert_eq!(true, true);
}
}
#[test]
fn base58_monero_work_if_string_not_base58_monero() {
let base58_monero_decoder = Decoder::<Base58MoneroDecoder>::new();
let result = base58_monero_decoder
.crack("hello good day!", &get_athena_checker())
.unencrypted_text;
if result.is_some() {
assert_eq!(true, true);
}
}
#[test]
fn base58_monero_handle_panic_if_emoji() {
let base58_monero_decoder = Decoder::<Base58MoneroDecoder>::new();
let result = base58_monero_decoder
.crack("😂", &get_athena_checker())
.unencrypted_text;
if result.is_some() {
assert_eq!(true, true);
}
}
}