Skip to content

Instantly share code, notes, and snippets.

@artygrand
Last active February 24, 2017 10:37
Show Gist options
  • Save artygrand/9e64915cfb8c7dc30ca503d9542bb175 to your computer and use it in GitHub Desktop.
Save artygrand/9e64915cfb8c7dc30ca503d9542bb175 to your computer and use it in GitHub Desktop.
Sample XOR encoder
<?php
$encoded = "..."; // <-- encoded string from the request
$decoded = "";
for( $i = 0; $i < strlen($encoded); $i++ ) {
$b = ord($encoded[$i]);
$a = $b ^ 123; // <-- must be same number used to encode the character
$decoded .= chr($a)
}
echo $decoded;
<html>
<head><title>Encoder</title></head>
<body>
<script type="text/javascript">
function enc(str) {
var encoded = "";
for (i=0; i<str.length;i++) {
var a = str.charCodeAt(i);
var b = a ^ 123; // bitwise XOR with any number, e.g. 123
encoded = encoded+String.fromCharCode(b);
}
return encoded;
}
var str = "hello world";
var encoded = enc(str);
alert(encoded); // shows encoded string
alert(enc(encoded)); // shows the original string again
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment