-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptstr.hpp
52 lines (45 loc) · 1.84 KB
/
cryptstr.hpp
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
#pragma once
#include <string>
#include <array>
#include <cstddef>
#include <type_traits>
#include <iostream>
#define finline __forceinline
namespace cryptstr {
class crypt {
public:
static constexpr auto time_str = __TIME__;
static constexpr int hours = (time_str[0] - '0') * 10 + (time_str[1] - '0');
static constexpr int minutes = (time_str[3] - '0') * 10 + (time_str[4] - '0');
static constexpr int seconds = (time_str[6] - '0') * 10 + (time_str[7] - '0');
static constexpr int randTime = (hours * minutes * seconds);
static constexpr unsigned long long a = 16264525ULL;
static constexpr unsigned long long c = 8013904223ULL;
static constexpr unsigned long long m = 0xFFFFFFFFF;
static constexpr int rkey = ((((a * randTime + c) % m) % 3ULL)) * 0xFF;
template <typename T, size_t N>
static constexpr std::array<T, N> xorencrypt(const T(&str)[N]) noexcept {
std::array<T, N> result{};
for (size_t i = 0; i < N - 1 && str[i] != '\0'; ++i) {
result[i] = str[i] ^ rkey;
}
return result;
}
template <typename T, size_t N>
static constexpr std::array<T, N> xordecrypt(const std::array<T, N>& enc) noexcept {
std::array<T, N> result{};
for (size_t i = 0; i < N - 1 && enc[i] != '\0'; ++i) {
result[i] = enc[i] ^ rkey;
}
return result;
}
};
}
#define crypt_(str) ([]() noexcept { \
using str_type = std::remove_cv_t<std::remove_pointer_t<decltype(str)>>; \
constexpr size_t size = sizeof(str) / sizeof(str[0]); \
using crypt_type = ::cryptstr::crypt; \
constexpr auto encrypted = crypt_type::xorencrypt(str); \
return crypt_type::xordecrypt(encrypted).data(); \
}())
#define crypt(str) (crypt_(str))