-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheGuardianAngel.cpp
216 lines (186 loc) · 13.4 KB
/
TheGuardianAngel.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <fstream>
#include <cstring>
#include <cryptopp/modes.h>
#include <cryptopp/aes.h>
#include <cryptopp/twofish.h>
#include <cryptopp/des.h>
#include <cryptopp/blowfish.h>
#include <cryptopp/files.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <cryptopp/osrng.h>
using namespace std;
using namespace CryptoPP;
void banner() {
std::cout << R"(
$$$$$$$$\ $$\ $$$$$$\ $$\ $$\ $$$$$$\ $$\
\__$$ __|$$ | $$ __$$\ $$ |\__| $$ __$$\ $$ |
$$ | $$$$$$$\ $$$$$$\ $$ / \__|$$\ $$\ $$$$$$\ $$$$$$\ $$$$$$$ |$$\ $$$$$$\ $$$$$$$\ $$ / $$ |$$$$$$$\ $$$$$$\ $$$$$$\ $$ |
$$ | $$ __$$\ $$ __$$\ $$ |$$$$\ $$ | $$ | \____$$\ $$ __$$\ $$ __$$ |$$ | \____$$\ $$ __$$\ $$$$$$$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ |
$$ | $$ | $$ |$$$$$$$$ | $$ |\_$$ |$$ | $$ | $$$$$$$ |$$ | \__|$$ / $$ |$$ | $$$$$$$ |$$ | $$ | $$ __$$ |$$ | $$ |$$ / $$ |$$$$$$$$ |$$ |
$$ | $$ | $$ |$$ ____| $$ | $$ |$$ | $$ |$$ __$$ |$$ | $$ | $$ |$$ |$$ __$$ |$$ | $$ | $$ | $$ |$$ | $$ |$$ | $$ |$$ ____|$$ |
$$ | $$ | $$ |\$$$$$$$\ \$$$$$$ |\$$$$$$ |\$$$$$$$ |$$ | \$$$$$$$ |$$ |\$$$$$$$ |$$ | $$ | $$ | $$ |$$ | $$ |\$$$$$$$ |\$$$$$$$\ $$ |
\__| \__| \__| \_______| \______/ \______/ \_______|\__| \_______|\__| \_______|\__| \__| \__| \__|\__| \__| \____$$ | \_______|\__|
$$\ $$ |
\$$$$$$ |
\______/
+-+-+-+ +-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+-+-+
|T|h|e| |G|a|t|e| |O|f| |E|n|c|r|y|p|t|i|o|n|
+-+-+-+ +-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+-+-+
Author : Mohamed Ashraf [TheKnower0x0]
Version: 1.1
GitHub : https://github.com/TheKnower0x0/The-Guardian-Angel
)" << '\n';
}
void PrintEncryptBanner() {
cout << R"(
██╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗ ███████╗███╗ ██╗ ██████╗██████╗ ██╗ ██╗██████╗ ████████╗██╗ ██████╗ ███╗ ██╗ ██╗
██║ ██║██╔══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔════╝████╗ ██║██╔════╝██╔══██╗╚██╗ ██╔╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ ██║
███████║███████║██████╔╝██████╔╝ ╚████╔╝ █████╗ ██╔██╗ ██║██║ ██████╔╝ ╚████╔╝ ██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║ ██║
██╔══██║██╔══██║██╔═══╝ ██╔═══╝ ╚██╔╝ ██╔══╝ ██║╚██╗██║██║ ██╔══██╗ ╚██╔╝ ██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║ ╚═╝
██║ ██║██║ ██║██║ ██║ ██║ ███████╗██║ ╚████║╚██████╗██║ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝
)" << '\n';
}
void printDecryptionBanner() {
cout << R"(
██╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ███████╗ ██████╗██████╗ ██╗ ██╗██████╗ ████████╗██╗ ██████╗ ███╗ ██╗ ██╗
██║ ██║██╔══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔══██╗██╔════╝██╔════╝██╔══██╗╚██╗ ██╔╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ ██║
███████║███████║██████╔╝██████╔╝ ╚████╔╝ ██║ ██║█████╗ ██║ ██████╔╝ ╚████╔╝ ██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║ ██║
██╔══██║██╔══██║██╔═══╝ ██╔═══╝ ╚██╔╝ ██║ ██║██╔══╝ ██║ ██╔══██╗ ╚██╔╝ ██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║ ╚═╝
██║ ██║██║ ██║██║ ██║ ██║ ██████╔╝███████╗╚██████╗██║ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝
)" << '\n';
}
void printExitBanner() {
cout << R"(
░▒▓███████▓▒░▒▓████████▓▒░▒▓████████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓██████▓▒░░▒▓██████▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓███████▓▒░░▒▓████████▓▒░▒▓████████▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
)" << '\n';
}
void AdjustKeyForAlgorithm(int choice, const string& password, SecByteBlock& key) {
switch (choice) {
case 2: // Twofish
key.CleanNew(Twofish::DEFAULT_KEYLENGTH);
break;
case 3: // Triple DES
key.CleanNew(DES_EDE3::DEFAULT_KEYLENGTH);
break;
case 4: // Blowfish
key.CleanNew(Blowfish::DEFAULT_KEYLENGTH);
break;
default: // AES
key.CleanNew(AES::DEFAULT_KEYLENGTH);
break;
}
size_t bytesToCopy = std::min(password.size(), key.size());
memcpy(key, password.data(), bytesToCopy);
}
void EncryptOrDecrypt(const string& filepath, int choice, const string& password, bool encrypt) {
string inputFile = filepath;
string outputFile = filepath + (encrypt ? ".enc" : ".dec");
ifstream inFile(inputFile, ios::binary);
ofstream outFile(outputFile, ios::binary);
string input((istreambuf_iterator<char>(inFile)), istreambuf_iterator<char>());
string output;
SecByteBlock key(AES::DEFAULT_KEYLENGTH);
AdjustKeyForAlgorithm(choice, password, key);
CryptoPP::byte iv[AES::BLOCKSIZE];
memset(iv, 0x00, AES::BLOCKSIZE);
try {
if (choice == 1) { // AES
if (encrypt) {
CBC_Mode<AES>::Encryption enc;
enc.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(enc, new StringSink(output)));
} else {
CBC_Mode<AES>::Decryption dec;
dec.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(dec, new StringSink(output)));
}
} else if (choice == 2) { // Twofish
if (encrypt) {
CBC_Mode<Twofish>::Encryption enc;
enc.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(enc, new StringSink(output)));
} else {
CBC_Mode<Twofish>::Decryption dec;
dec.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(dec, new StringSink(output)));
}
} else if (choice == 3) { // Triple DES
if (encrypt) {
CBC_Mode<DES_EDE3>::Encryption enc;
enc.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(enc, new StringSink(output)));
} else {
CBC_Mode<DES_EDE3>::Decryption dec;
dec.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(dec, new StringSink(output)));
}
} else if (choice == 4) { // Blowfish
if (encrypt) {
CBC_Mode<Blowfish>::Encryption enc;
enc.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(enc, new StringSink(output)));
} else {
CBC_Mode<Blowfish>::Decryption dec;
dec.SetKeyWithIV(key, key.size(), iv);
StringSource s(input, true, new StreamTransformationFilter(dec, new StringSink(output)));
}
}
outFile.write(output.data(), output.size());
cout << (encrypt ? "Encryption" : "Decryption") << " completed successfully." << endl;
if (encrypt) {
PrintEncryptBanner();
} else {
printDecryptionBanner();
}
} catch (const CryptoPP::Exception& e) {
cerr << (encrypt ? "Encryption" : "Decryption") << " failed: " << e.what() << endl;
}
inFile.close();
outFile.close();
}
int main() {
banner();
cout << "Enter 'e' to encrypt or 'd' to decrypt: ";
char option;
cin >> option;
bool encrypt = (option == 'e');
if (option != 'e' && option != 'd') {
cerr << "Invalid option." << endl;
return 1;
}
cout << "[1] AES" << endl;
cout << "[2] Twofish" << endl;
cout << "[3] Triple DES" << endl;
cout << "[4] Blowfish" << endl;
cout << "[0] Exit" << endl;
cout << "Choose an algorithm: ";
int algoChoice;
cin >> algoChoice;
if (algoChoice == 0) {
cout << "Exiting the tool." << endl;
printExitBanner();
return 0;
}
if (algoChoice < 1 || algoChoice > 4) {
cerr << "Invalid algorithm choice." << endl;
return 1;
}
string filepath;
cout << "Enter the file path: ";
cin >> filepath;
string password;
cout << "Enter the security key password: ";
cin >> password;
EncryptOrDecrypt(filepath, algoChoice, password, encrypt);
return 0;
}