<?
// Translates haxor to english
function fixhaxor($haxor)
{
$singlecharMap = array(
"@" => "a",
"4" => "a",
"8" => "b",
"(" => "c",
"3" => "e",
"6" => "g",
"!" => "i",
"|" => "i",
// this could be i or l
"1" => "l",
"0" => "o",
"5" => "s",
"$" => "s",
"7" => "t",
"2" => "z",
);
$multicharMap = array(
'|_|' => 'u',
'\/' => 'v',
'|/|' => 'n',
'|\|' => 'n',
'1\\1' => 'n',
'|)' => 'd',
'1)' => 'd',
'|-|' => 'h',
'c|' => 'd',
'|\/|' => 'm',
'/\/\\' => 'm',
'\'/' => 'y',
'/-\\' => 'a',
);
$wordMap = array(
'ur' => 'you\'re',
'u' => 'you',
'r' => 'are',
'lt' => 'it',
'noob' => 'moron',
'noobs' => 'morons',
'leet' => 'awesome',
'phor' => 'for',
);
$haxorWords = preg_split("/[ \t]+/", $haxor);
foreach ($haxorWords as $haxorWord) {
// if it ends with a period, strip it off as actual punctuation (ha!)
// so we can translate and add it back later
$hasPeriod = false;
if (preg_match('/^(.*)\./', $haxorWord, $matches)) {
$hasPeriod=true;
$haxorWord = $matches[1];
}
if (preg_match("/^[0-9\.\,]+$/", $haxorWord)) {
// figure out if it is actually a number. This isn't incredibly
// easy since haxor words could also be completely numbers. Since
// punctuation has little meaning, just wing it.
switch ($haxorWord) {
// fix some common ones
case '4':
$translated[] = 'a';
break;
case '411':
$translated[] = 'all';
break;
case '50':
$translated[] = 'so';
break;
// pass it through and hope
default:
$translated[] = $haxorWord;
break;
}
} else {
// convert our multibyte chars based on the map
foreach ($multicharMap as $charHaxor => $charEnglish) {
$haxorWord = preg_replace('%' . preg_quote($charHaxor, '%') . '%', $charEnglish, $haxorWord);
}
// now replace our single byte chars based on the map
foreach ($singlecharMap as $charHaxor => $charEnglish) {
$tmpWord = '';
for ($ctr = 0; $ctr < strlen($haxorWord); $ctr++) {
$tmpWord .= (isset($singlecharMap[$haxorWord[$ctr]])) ? $singlecharMap[$haxorWord[$ctr]] : $haxorWord[$ctr];
}
// don't even bother trying to preserve case
$haxorWord = strtolower($tmpWord);
}
// if the word ends in a z.... fix it...
$haxorWord = preg_replace('/z$/', 's', $haxorWord);
// lastly, check it against our word map
if (isset($wordMap[$haxorWord])) {
$haxorWord = $wordMap[$haxorWord];
}
$translated[] = $haxorWord;
}
if ($hasPeriod) {
$lastword = count($translated)-1;
$translated[$lastword] = $translated[$lastword] .= ".";
}
}
return(implode(" ", $translated));
}
// translates english to haxor
function genhaxor($english, $level = 1, $allowMb = false)
{
$letterMap = array(
"a" => array('@'),
"e" => array('3'),
"o" => array('0'),
"s" => array('5', '$'),
"t" => array('7'),
"b" => array('8'),
);
$letterMapMb = array(
"a" => array('@', '/-\\'),
"e" => array('3'),
"o" => array('0'),
"s" => array('5', '$'),
"t" => array('7'),
"h" => array('|-|'),
"u" => array('|_|'),
"m" => array('/\/\\', '|\/|'),
"v" => array('\/'),
"w" => array('\/\/'),
"b" => array('8'),
"d" => array('c|'),
);
$map = $allowMb ? $letterMapMb : $letterMap; // select the map to use
// loop through every letter
$haxor = '';
for ($ctr = 0; $ctr < strlen($english); $ctr++) {
$letter = $english[$ctr];
$tmpLetter = '';
$letter = strtolower($letter); // like capitalization matters
// determine rand max based on obfuscation level argument
if (mt_rand(0, $level)) {
// 50/50 shot at capitalizing
$tmpLetter = $letter;
if (mt_rand(0, 1)) {
$tmpLetter = strtoupper($letter);
}
if (isset($map[$letter])) {
// just pick one... it doesn't matter which
$tmpLetter = $map[$letter][mt_rand(0, count($map[$letter])-1)];
}
$haxor .= addslashes($tmpLetter);
} else {
$haxor .= $letter;
}
}
return($haxor);
}
?>