Skip to content

Commit 9dfaba6

Browse files
committed
Xorstr + File test
1 parent 80309ec commit 9dfaba6

File tree

5 files changed

+177
-6
lines changed

5 files changed

+177
-6
lines changed

Source/Randomize.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<SDLCheck>true</SDLCheck>
131131
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132132
<ConformanceMode>true</ConformanceMode>
133+
<LanguageStandard>stdcpp17</LanguageStandard>
133134
</ClCompile>
134135
<Link>
135136
<SubSystem>Console</SubSystem>
@@ -145,6 +146,7 @@
145146
<ItemGroup>
146147
<ClInclude Include="Helpers.h" />
147148
<ClInclude Include="stdafx.h" />
149+
<ClInclude Include="xorstr.hpp" />
148150
</ItemGroup>
149151
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
150152
<ImportGroup Label="ExtensionTargets">

Source/Randomize.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
<ItemGroup>
88
<ClInclude Include="stdafx.h" />
99
<ClInclude Include="Helpers.h" />
10+
<ClInclude Include="xorstr.hpp" />
1011
</ItemGroup>
1112
</Project>

Source/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#include "stdafx.h"
22

3-
43
int main(int argc, char* argv[])
54
{
6-
SetConsoleTitleA("Randomizer []");
5+
SetConsoleTitleA(_xor_("Randomizer []").c_str());
76

8-
std::string GUID = Helpers::CreateGuid();
7+
//std::string GUID = Helpers::CreateGuid();
98

10-
std::cout << GUID << std::endl;
11-
getchar();
9+
string NiggerPath = _xor_("C:\\Users\\ykaan\\Documents\\GitHub\\cpp-c-randomizer\\Example-Project\\").c_str();
10+
for (const auto& entry : fs::directory_iterator(NiggerPath))
11+
{
12+
std::string CurrentPath = entry.path().string();
13+
CurrentPath.replace(CurrentPath.find(NiggerPath), NiggerPath.length(), "");
14+
std::cout << CurrentPath << std::endl;
15+
}
1216

1317

1418
}

Source/stdafx.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
// Common Includes
33
#include <windows.h>
44
#include <iomanip>
5+
#include <cstdint>
56

67
// STD
8+
#include <stdio.h>
79
#include <string>
10+
#include <filesystem>
811

912
// Stream
1013
#include <iostream>
@@ -13,5 +16,9 @@
1316
#include <ostream>
1417

1518
// User Define
16-
19+
#include "xorstr.hpp"
1720
#include "Helpers.h"
21+
22+
// Namespace
23+
using namespace std;
24+
namespace fs = std::filesystem;

Source/xorstr.hpp

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <utility>
5+
6+
namespace
7+
{
8+
constexpr int const_atoi(char c)
9+
{
10+
return c - '0';
11+
}
12+
}
13+
14+
#ifdef _MSC_VER
15+
#define ALWAYS_INLINE __forceinline
16+
#else
17+
#define ALWAYS_INLINE __attribute__((always_inline))
18+
#endif
19+
20+
template<typename _string_type, size_t _length>
21+
class _Basic__xor_
22+
{
23+
using value_type = typename _string_type::value_type;
24+
static constexpr auto _length_minus_one = _length - 1;
25+
26+
public:
27+
constexpr ALWAYS_INLINE _Basic__xor_(value_type const (&str)[_length])
28+
: _Basic__xor_(str, std::make_index_sequence<_length_minus_one>())
29+
{
30+
31+
}
32+
33+
inline auto c_str() const
34+
{
35+
decrypt();
36+
37+
return data;
38+
}
39+
40+
inline auto str() const
41+
{
42+
decrypt();
43+
44+
return _string_type(data, data + _length_minus_one);
45+
}
46+
47+
inline operator _string_type() const
48+
{
49+
return str();
50+
}
51+
52+
private:
53+
template<size_t... indices>
54+
constexpr ALWAYS_INLINE _Basic__xor_(value_type const (&str)[_length], std::index_sequence<indices...>)
55+
: data{ crypt(str[indices], indices)..., '\0' },
56+
encrypted(true)
57+
{
58+
59+
}
60+
61+
static constexpr auto XOR_KEY = static_cast<value_type>(
62+
const_atoi(__TIME__[7]) +
63+
const_atoi(__TIME__[6]) * 10 +
64+
const_atoi(__TIME__[4]) * 60 +
65+
const_atoi(__TIME__[3]) * 600 +
66+
const_atoi(__TIME__[1]) * 3600 +
67+
const_atoi(__TIME__[0]) * 36000
68+
);
69+
70+
static ALWAYS_INLINE constexpr auto crypt(value_type c, size_t i)
71+
{
72+
return static_cast<value_type>(c ^ (XOR_KEY + i));
73+
}
74+
75+
inline void decrypt() const
76+
{
77+
if (encrypted)
78+
{
79+
for (size_t t = 0; t < _length_minus_one; t++)
80+
{
81+
data[t] = crypt(data[t], t);
82+
}
83+
encrypted = false;
84+
}
85+
}
86+
87+
mutable value_type data[_length];
88+
mutable bool encrypted;
89+
};
90+
//---------------------------------------------------------------------------
91+
template<size_t _length>
92+
using _xor_A = _Basic__xor_<std::string, _length>;
93+
template<size_t _length>
94+
using _xor_W = _Basic__xor_<std::wstring, _length>;
95+
template<size_t _length>
96+
using _xor_U16 = _Basic__xor_<std::u16string, _length>;
97+
template<size_t _length>
98+
using _xor_U32 = _Basic__xor_<std::u32string, _length>;
99+
//---------------------------------------------------------------------------
100+
template<typename _string_type, size_t _length, size_t _length2>
101+
inline auto operator==(const _Basic__xor_<_string_type, _length>& lhs, const _Basic__xor_<_string_type, _length2>& rhs)
102+
{
103+
static_assert(_length == _length2, "_xor_== different length");
104+
105+
return _length == _length2 && lhs.str() == rhs.str();
106+
}
107+
//---------------------------------------------------------------------------
108+
template<typename _string_type, size_t _length>
109+
inline auto operator==(const _string_type& lhs, const _Basic__xor_<_string_type, _length>& rhs)
110+
{
111+
return lhs.size() == _length && lhs == rhs.str();
112+
}
113+
//---------------------------------------------------------------------------
114+
template<typename _stream_type, typename _string_type, size_t _length>
115+
inline auto& operator<<(_stream_type& lhs, const _Basic__xor_<_string_type, _length>& rhs)
116+
{
117+
lhs << rhs.c_str();
118+
119+
return lhs;
120+
}
121+
//---------------------------------------------------------------------------
122+
template<typename _string_type, size_t _length, size_t _length2>
123+
inline auto operator+(const _Basic__xor_<_string_type, _length>& lhs, const _Basic__xor_<_string_type, _length2>& rhs)
124+
{
125+
return lhs.str() + rhs.str();
126+
}
127+
//---------------------------------------------------------------------------
128+
template<typename _string_type, size_t _length>
129+
inline auto operator+(const _string_type& lhs, const _Basic__xor_<_string_type, _length>& rhs)
130+
{
131+
return lhs + rhs.str();
132+
}
133+
//---------------------------------------------------------------------------
134+
template<size_t _length>
135+
constexpr ALWAYS_INLINE auto _xor_(char const (&str)[_length])
136+
{
137+
return _xor_A<_length>(str);
138+
}
139+
//---------------------------------------------------------------------------
140+
template<size_t _length>
141+
constexpr ALWAYS_INLINE auto _xor_(wchar_t const (&str)[_length])
142+
{
143+
return _xor_W<_length>(str);
144+
}
145+
//---------------------------------------------------------------------------
146+
template<size_t _length>
147+
constexpr ALWAYS_INLINE auto _xor_(char16_t const (&str)[_length])
148+
{
149+
return _xor_U16<_length>(str);
150+
}
151+
//---------------------------------------------------------------------------
152+
template<size_t _length>
153+
constexpr ALWAYS_INLINE auto _xor_(char32_t const (&str)[_length])
154+
{
155+
return _xor_U32<_length>(str);
156+
}
157+
//---------------------------------------------------------------------------

0 commit comments

Comments
 (0)