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
extern crate hex;
extern crate words;
use hex::decode;
use words::*;
pub struct Sbxor {
pub encoded_str: String,
pub decoded_strs: Vec<String>,
pub is_english: bool,
pub encoding_byte: Option<u8>
}
impl Sbxor {
#[allow(unused)]
pub fn new() -> Sbxor {
Sbxor {
encoded_str: String::new(),
decoded_strs: vec![],
is_english: false,
encoding_byte: None
}
}
pub fn create(encoded_str: String) -> Sbxor {
Sbxor {
encoded_str: encoded_str,
decoded_strs: vec![],
is_english: false,
encoding_byte: None
}
}
pub fn decode_sbxor(&mut self) {
let mut wordy = Words::new();
wordy.populate();
for i in 0..255 {
let vec = decode(&self.encoded_str).unwrap();
let vec: Vec<u8> = vec.into_iter().map(|x| x ^ i).collect();
let chrs_after_xor: Vec<char> = vec.into_iter().map(|x| x as char).collect();
let mut soln: Vec<char> = vec![];
for chr in chrs_after_xor {
if (chr.is_ascii() && chr.is_ascii_alphanumeric()) || chr == ' ' {
soln.push(chr.to_lowercase().to_string().chars().next().unwrap());
}
}
let s: String = soln.into_iter().collect();
if is_english(&s, &wordy) {
self.is_english = true;
self.encoding_byte = Some(i);
}
self.decoded_strs.push(s);
}
}
pub fn decode_sbxor_char(&mut self, encoding_byte: u8) {
let mut wordy = Words::new();
wordy.populate();
let vec = decode(&self.encoded_str).unwrap();
let vec: Vec<u8> = vec.into_iter().map(|x| x ^ encoding_byte).collect();
let chrs_after_xor: Vec<char> = vec.into_iter().map(|x| x as char).collect();
let mut soln: Vec<char> = vec![];
for chr in chrs_after_xor {
if (chr.is_ascii() && chr.is_ascii_alphanumeric()) || chr == ' ' {
soln.push(chr.to_lowercase().to_string().chars().next().unwrap());
}
}
let s: String = soln.into_iter().collect();
self.decoded_strs.push(s);
}
}
pub fn is_english(s: &String, wordy: &Words) -> bool{
let s: &str = &*s;
let iter = s.split_whitespace();
for word in iter {
if word.len() > 3 {
if wordy.exists(word.to_string()) {
return true;
}
}
}
false
}