XOR is a logical operation, pronounced exclusive or. It can be used to cipher messages simply and fast.
<?php
$xor_key = 's9k7a8l4j';
$string = 'string';
function xorIt($string, $key, $type = 0)
{
$sLength = strlen($string);
$xLength = strlen($key);
for($i = 0; $i < $sLength; $i++) {
for($j = 0; $j < $xLength; $j++) {
if ($type == 1) {
//decrypt
$string[$i] = $key[$j]^$string[$i];
} else {
//crypt
$string[$i] = $string[$i]^$key[$j];
}
}
}
return $string;
}
$signal = base64_encode(xorIt($string, $xor_key));
echo $signal . PHP_EOL;
$string = xorIt(base64_decode($signal), $xor_key, 1);
echo $string . PHP_EOL;