Encrypted results will appear here
XOR Encryption
Encrypt and decrypt data using XOR cipher with customizable key.
Input
History
About XOR Encryption
This tool uses position-based XOR encryption. Each byte is XORed with both the key and its position index, providing better obfuscation than simple XOR.
encrypted[i] = data[i] ^ key ^ (i & 0xFF)
Decoder Examples
Use these functions to decode data encrypted with this tool. Example key: 0x33
C++
#include <string>
std::string xorDecode(const unsigned char* data, size_t length) {
std::string result;
result.reserve(length);
const unsigned char key = 0x33;
for (size_t i = 0; i < length; ++i) {
result += (char)(data[i] ^ key ^ (i & 0xFF));
}
return result;
}
// Usage:
// unsigned char encrypted[] = {0x96, 0x94, 0x92, ...};
// std::string decoded = xorDecode(encrypted, sizeof(encrypted));
Java
public static String xorDecode(byte[] data) {
StringBuilder result = new StringBuilder();
final int key = 0x33;
for (int i = 0; i < data.length; i++) {
result.append((char)((data[i] & 0xFF) ^ key ^ (i & 0xFF)));
}
return result.toString();
}
// Usage:
// byte[] encrypted = {(byte)0x96, (byte)0x94, (byte)0x92, ...};
// String decoded = xorDecode(encrypted);
PHP
function xorDecode(array $data): string {
$result = '';
$key = 0x33;
for ($i = 0; $i < count($data); $i++) {
$result .= chr($data[$i] ^ $key ^ ($i & 0xFF));
}
return $result;
}
// Usage:
// $encrypted = [0x96, 0x94, 0x92, ...];
// $decoded = xorDecode($encrypted);
JavaScript
function xorDecode(data) {
const key = 0x33;
const decoded = new Uint8Array(data.length);
for (let i = 0; i < data.length; i++) {
decoded[i] = data[i] ^ key ^ (i & 0xFF);
}
return new TextDecoder().decode(decoded);
}
// Usage:
// const encrypted = [0x96, 0x94, 0x92, ...];
// const decoded = xorDecode(encrypted);
Common Uses
- Simple data obfuscation
- Configuration file protection
- Binary data manipulation
- String hiding in compiled code