-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_1_4.cpp
59 lines (46 loc) · 1.22 KB
/
set_1_4.cpp
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
#include <cassert>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include "byte_vector.hpp"
#include "hex.hpp"
#include "xor.hpp"
#include "base64.hpp"
#include "byte_freqency.hpp"
using namespace std::string_literals;
struct is_ascii_predicate {
bool operator () (const byte& b) const {
return (b >= 32 && b < 127) || b == 0;
}
};
int main() {
auto filename = "4.txt"s;
std::vector<std::string> lines;
{
std::ifstream file(filename);
while (!file.fail()) {
std::string line;
file >> line;
if (file.fail()) {
break;
}
//std::cout << line << std::endl;
lines.push_back(line);
}
file.close();
}
for (auto line: lines) {
auto bytes = hex_to_bytes(line);
auto freq = map_byte_frequency(bytes);
auto freq_vec = map_to_vector(freq);
sort_freq_vec_desc(freq_vec);
auto decipher = bytes ^ freq_vec[0].first;
auto str = bytes_to_str(decipher);
if (std::all_of(begin(str), end(str), is_ascii_predicate())) {
std::cout << decipher << std::endl;
}
}
return 0;
}