Developer knowledge network · moderated exchange

UnreliableCode-Community

Community für Entwicklerforschung, Reverse Engineering und Codierung

Knowledge indexLive
4Categories
919Threads
2.8KBeiträge
Release

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

vtable_slayer
Senior Reverser
MEMBER
Vertreter: 215
Beitrittsdatum: Mar 2018
Beiträge: 86
Danke: 61
Vor 2 Wochen · 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
Vertreter: 210
Beitrittsdatum: Dec 2019
Beiträge: 11
Danke: 51
Vor 2 Wochen · 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
Vertreter: 181
Beitrittsdatum: Jul 2019
Beiträge: 21
Danke: 50
Vor 2 Wochen · Aug 5, 2026 10:35 PM
#3

Clean compile-time macro.