| 39 | |
| 40 | |
| 41 | void strings_obfuscation() { |
| 42 | // Obfuscate a string literal |
| 43 | std::cout << "abc"_obf << '\n'; |
| 44 | describe("abc"_obf); |
| 45 | |
| 46 | // Using std::format |
| 47 | std::cout << std::format("{}\n", "abc"_obf); |
| 48 | |
| 49 | // Obfuscate a string literal and describe it after deobfuscation |
| 50 | auto s1{"0123456789"_obf}; |
| 51 | describe(s1); |
| 52 | std::cout << s1 << "\n"; |
| 53 | describe(s1); |
| 54 | |
| 55 | // Construct explicitly an ObfuscatedString |
| 56 | auto s2 = ObfuscatedString("abcd", {1, KeyAlgorithm::IDENTITY, DataAlgorithm::XOR}); |
| 57 | std::cout << s2 << '\n'; |
| 58 | describe(s2); |
| 59 | |
| 60 | // Construct explicitly an ObfuscatedString with precise obfuscation parameters |
| 61 | static constexpr Parameters params[] = { |
| 62 | {.key=1, .key_algo=KeyAlgorithm::IDENTITY, .data_algo=DataAlgorithm::XOR}, |
| 63 | {.key=2, .key_algo=KeyAlgorithm::IDENTITY, .data_algo=DataAlgorithm::XOR} |
| 64 | }; |
| 65 | auto s3 = ObfuscatedString("abcde", params); |
| 66 | describe(s3); |
| 67 | std::cout << s3 << '\n'; |
| 68 | describe(s3); |
| 69 | |
| 70 | static constexpr auto s4 = "An immutable compile-time string"_obf; |
| 71 | describe(s4); |
| 72 | // It is not possible to use directly s4 since it is immutable: |
| 73 | // std::cout << s4 << '\n'; // Compilation failure |
| 74 | // So use decode() instead: |
| 75 | std::cout << s4.decode() << '\n'; |
| 76 | } |
| 77 | |
| 78 | void blocks_obfuscation() { |
| 79 | static constexpr auto rcon0 = ObfuscatedBytes{"01 02 04 08 10 20 40 80 1b 36"}; |
no test coverage detected