-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalyst.cpp
88 lines (74 loc) · 2.98 KB
/
catalyst.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
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
#include <iostream>
#include <filesystem>
#include <fstream>
#include <unordered_set>
#include <vector>
#include "catalyst.hpp"
#include "commandline_args.hpp"
inline void print_vector(const std::vector<uint8_t>& data) {
printf("\t(string) ");
for (const auto& e : data) {
printf("%c", (char)e);
}
printf("\n");
printf("\t(hexadecimal) 0x");
for (const auto& e : data) {
printf("%02x", (uint16_t)e);
}
printf("\n");
}
int main(int argc, char* argv[]) {
_execution_context ectx = process_arguments(argc, argv);
const std::string& data = ectx.data;
const std::string& key = ectx.key;
std::cout << "\n";
std::cout << "provided key:\n";
print_vector(std::vector<uint8_t>((uint8_t*)key.data(), (uint8_t*)key.data() + key.size()));
std::cout << std::endl;
if (ectx.mode == _internal_mode::encryption) {
std::cout << "mode: encryption\n\n";
std::cout << "input data:\n";
std::vector<uint8_t> raw_data((uint8_t*)data.data(), (uint8_t*)data.data() + data.size());
print_vector(raw_data);
std::cout << std::endl;
std::vector<uint8_t> cipher = catalyst::encrypt(raw_data.data(), raw_data.size(), (uint8_t*)key.data(), key.size());
std::cout << "output cipher:\n";
if (!ectx.output_to_file) {
print_vector(cipher);
}
else {
std::ofstream output_f(ectx.output_file_name, std::ios::binary);
if (output_f) {
output_f.write((char*)cipher.data(), cipher.size() / sizeof(char));
std::cout << "Output written to file: " << ectx.output_file_name << std::endl;
}
else {
std::cerr << "Unable to write output to file: " << ectx.output_file_name << std::endl;
return -1;
}
}
} else if (ectx.mode == _internal_mode::decryption) {
std::cout << "mode: decryption\n\n";
std::cout << "input data:\n";
std::vector<uint8_t> raw_data((uint8_t*)data.data(), (uint8_t*)data.data() + data.size());
print_vector(raw_data);
std::cout << std::endl;
std::vector<uint8_t> recovered = catalyst::decrypt((uint8_t*)data.data(), data.size(), (uint8_t*)key.data(), key.size());
std::cout << "recovered data:\n";
if (!ectx.output_to_file) {
print_vector(recovered);
}
else {
std::ofstream output_f(ectx.output_file_name, std::ios::binary);
if (output_f) {
output_f.write((char*)recovered.data(), recovered.size() / sizeof(char));
std::cout << "Output written to file: " << ectx.output_file_name << std::endl;
}
else {
std::cerr << "Unable to write output to file: " << ectx.output_file_name << std::endl;
return -1;
}
}
}
return 0;
}