2주 전 · Aug 5, 2026 9:39 AM
Zero-dependency compile-time string encryption using C++20 consteval:
CPP
template<size_t N, uint8_t Key>
struct EncryptedString {
uint8_t data[N];
consteval EncryptedString(const char(&str)[N]) {
for (size_t i = 0; i < N; ++i) data[i] = str[i] ^ (Key + (uint8_t)i);
}
std::string Decrypt() const {
std::string s(N - 1, '\0');
for (size_t i = 0; i < N - 1; ++i) s[i] = data[i] ^ (Key + (uint8_t)i);
return s;
}
};
#define _XOR(str) []() -> std::string { static constexpr auto enc = EncryptedString<sizeof(str), 0x7A>(str); return enc.Decrypt(); }()All strings are scrambled in the compiled .rdata section and only decrypted on stack during execution!