Skip to content

Instantly share code, notes, and snippets.

@Cih2001
Last active July 3, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cih2001/f6adcfb29e3a9a0b0aafe7b1c263fbdc to your computer and use it in GitHub Desktop.
Save Cih2001/f6adcfb29e3a9a0b0aafe7b1c263fbdc to your computer and use it in GitHub Desktop.
#define KEY 0x55
template <unsigned int N>
struct obfuscator {
/*
* m_data stores the obfuscated string.
*/
char m_data[N] = {0};
/*
* Using constexpr ensures that the strings will be obfuscated in this
* constructor function at compile time.
*/
constexpr obfuscator(const char* data) {
/*
* Implement encryption algorithm here.
* Here we have simple XOR algorithm.
*/
for (unsigned int i = 0; i < N; i++) {
m_data[i] = data[i] ^ KEY;
}
}
};
int main() {
// Store "Hello" in obfuscated form using simple xor encryption.
constexpr auto obfuscated_str = obfuscator<6>("Hello");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment