Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created March 18, 2016 13:02
Show Gist options
  • Save AndyNovo/fdff34d0f4976e842358 to your computer and use it in GitHub Desktop.
Save AndyNovo/fdff34d0f4976e842358 to your computer and use it in GitHub Desktop.
<?php
function xorIt($charOne, $charTwo)
{
return $charOne ^ $charTwo;
}
function asciiValue($char)
{
return ord($char);
}
function encrypt($plainText)
{
$length = strlen($plainText);
$space = 0xA;
$cipherText = "";
for ($i = 0; $i < $length; $i++) {
if ($i + $space < $length - 1) {
$cipherText .= xorIt($plainText[$i], $plainText[$i + $space]);
} else {
$cipherText .= xorIt($plainText[$i], $plainText[$space]);
}
$space = (asciiValue($plainText[$i]) % 2 == 0 ? $space + 1 : $space - 1);
}
return bin2hex($cipherText);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment