Developer knowledge network ยท moderated exchange

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Knowledge indexLive
4Categories
919Threads
2.8KPosts
Release

C++20 consteval Compile-Time String Encryption Macro with XOR Permutation [v2.4 Technical Discussion]

vtable_slayer
Senior Reverser
MEMBER
Rep: 215
Join Date: Mar 2018
Posts: 86
Thanks: 61
2 weeks ago ยท Aug 5, 2026 9:39 AM
#1

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!

sig_scanner_sam
Pattern Master
MEMBER
Rep: 210
Join Date: Dec 2019
Posts: 11
Thanks: 51
2 weeks ago ยท Aug 5, 2026 2:04 PM
#2

Replaced skCrypt with this. Clean C++20 standard compliance with zero compiler warnings.

hook_doctor
Hooking Specialist
MEMBER
Rep: 181
Join Date: Jul 2019
Posts: 21
Thanks: 50
2 weeks ago ยท Aug 5, 2026 10:35 PM
#3

Clean compile-time macro.