-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobfuscate.cpp
More file actions
62 lines (60 loc) · 1.76 KB
/
obfuscate.cpp
File metadata and controls
62 lines (60 loc) · 1.76 KB
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
#include "header.h"
#include <algorithm>
void obfuscate(std::ifstream& in, BYTE b)
{
static std::vector<std::pair<std::string, std::string>> lib;
static bool add_to_lib{ false };
std::string bytes;
std::string letters{"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"};
static size_t counter{0};
std::string counterToChars;
if(!ispunct(b) && !isspace(b)) {
bytes += b;
while (!ispunct(in.peek()) && !isspace(in.peek())) {
bytes += in.get();
}
}
else {
std::cout << b;
return;
}
if (add_to_lib) {
//check if allready found
auto it = find_if(lib.begin(), lib.end(),
[&](const std::pair<std::string, std::string>& val) -> bool {
return val.first == bytes;
});
//if found, use that
if(it != lib.end()) {
std::cout << it->second;
}
//if not found, add to lib
else {
size_t temp{counter};
do {
counterToChars += letters[temp%letters.size()];
temp /= letters.size();
} while(temp != 0);
lib.emplace_back(std::make_pair(bytes, counterToChars));
std::cout << lib.back().second;
counter++;
}
add_to_lib = false;
}
else if (bytes == "const" || bytes == "var" || bytes == "let") {
add_to_lib = true;
std::cout << bytes;
}
else {
auto it = find_if(lib.begin(), lib.end(),
[&](const std::pair<std::string, std::string>& val) -> bool {
return val.first == bytes;
});
if(it != lib.end()) {
std::cout << it->second;
}
else {
std::cout << bytes;
}
}
}