Lightweight C++ byte-array obfuscation using XOR, byte-reversal, and a trailing 3‑byte signature. This is a simple educational utility; it is not a cryptographically secure algorithm.
src/
├─ bit_encryption.h
└─ bit_encryption.cpp
legacy/
└─ bit_encryption_legacy.cpp
example/
└─ example.cpp
LICENSE
README.md
.gitignore
Given input bytes and one or more key bytes:
- Builds an effective key stream of the same length as the input:
- If there are fewer keys than input bytes, keys are repeated (cycled).
- If there are more or equal keys, they are folded by XOR into positions modulo the input length.
- XORs each input byte with the corresponding effective key byte.
- Reverses the resulting byte order.
- Appends a 3‑byte signature
0x3B, 0x2D, 0x29to mark a valid ciphertext.
Decryption validates the signature, strips it, reverses the bytes, rebuilds the same effective key stream, and XORs to recover the original.
Error handling: on invalid input, methods return an empty vector.
Class: BitEncryption
-
std::vector<uint8_t> encrypt(const std::vector<uint8_t>& originalBytes, const std::vector<uint8_t>& keys);- Returns ciphertext with signature appended, or an empty vector on error.
-
std::vector<uint8_t> decrypt(const std::vector<uint8_t>& encryptedBytes, const std::vector<uint8_t>& keys);- Returns recovered plaintext, or an empty vector on error (e.g., missing/invalid signature).
-
std::vector<uint8_t> generateKeys(size_t count);- Generates
countrandom bytes in[0, 255]usingstd::random_devicewithstd::uniform_int_distribution(unbiased). On mainstream Windows/Linux,random_deviceis typically backed by the OS CSPRNG, but this isn’t guaranteed by the C++ standard.
- Generates
Signature bytes and size (for reference): 0x3B, 0x2D, 0x29 (size 3).
Compile and link src/bit_encryption.cpp with your application and include src/bit_encryption.h.
Replace example/example.cpp with your main.
- MSVC (Developer Command Prompt / PowerShell):
cl /std:c++17 /EHsc example/example.cpp src\bit_encryption.cpp /Fe:app.exe
- g++/clang++ (MinGW or Unix-like environments):
g++ -std=c++17 example/example.cpp src/bit_encryption.cpp -o app
- This is not secure encryption; it’s a simple XOR-based obfuscation with a fixed signature. Do not use for sensitive data.
- Keys may include 0 values. Allowing 0 ensures a full 8 bits of entropy per byte; XOR by 0 occurs with probability 1/256 and is expected.
- The key folding behavior when providing many keys is intentional; read the implementation if you need a different policy (e.g., truncate or hash keys).
This project is released under The Unlicense (public domain). See LICENSE or https://unlicense.org.