Skip to content

Instantly share code, notes, and snippets.

@AstDerek
Created March 12, 2012 07:25
Show Gist options
  • Save AstDerek/2020450 to your computer and use it in GitHub Desktop.
Save AstDerek/2020450 to your computer and use it in GitHub Desktop.
Simple XOR obfuscator
<?php
function xor_obfuscator ($string) {
if (!strlen($string)) {
return $string;
}
$key = ord($string{0});
$new = pack("C",
($key & 0xf0)
|
(
($key & 0x0f)
^
(($key >> 4) & 0x0f)
)
);
for ($c=1;$c<strlen($string);$c++) {
$new .= pack("C",ord($string{$c}) ^ $key);
}
return base64_encode($new);
}
function xor_deobfuscator ($string) {
$string = base64_decode($string);
if (!strlen($string)) {
return $string;
}
$keys = unpack("C*",$string);
$key = $keys[1];
$key = ($key & 0xf0)
|
(
($key & 0x0f)
^
(
($key >> 4)
&
0x0f
)
);
$new = chr($key);
for ($c=2;$c<=count($keys);$c++) {
$new .= chr($keys[$c] ^ $key);
}
return $new;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment