Repository navigation
Expand file tree
/
Copy pathobfuscate.cpp
More file actions
75 lines (73 loc) · 1.97 KB
/
Copy pathobfuscate.cpp
File metadata and controls
75 lines (73 loc) · 1.97 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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "header.hpp"
#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;
}
}
}