JS代码,V8执行
function hexXor(str1, str2) {
var result = ''
for (var i = 0; i < str1.length && i < str2.length; i += 2) {
var substring1 = parseInt(str1.slice(i, i + 2), 16);
var substring2 = parseInt(str2.slice(i, i + 2), 16);
var xorResult = (substring1 ^ substring2).toString(16);
if (xorResult.length == 1) {
xorResult = '0' + xorResult;
}
result += xorResult;
}
return result;
}
function unsbox(str) {
var box = [0xf, 0x23, 0x1d, 0x18, 0x21, 0x10, 0x1, 0x26, 0xa, 0x9, 0x13, 0x1f, 0x28, 0x1b, 0x16, 0x17, 0x19, 0xd, 0x6, 0xb, 0x27, 0x12, 0x14, 0x8, 0xe, 0x15, 0x20, 0x1a, 0x2, 0x1e, 0x7, 0x4, 0x11, 0x5, 0x3, 0x1c, 0x22, 0x25, 0xc, 0x24];
var mappedArray = [];
for (var i = 0; i < str.length; i++) {
var charValue = str[i];
for (var j = 0; j < box.length; j++) {
if (box[j] === i + 1) {
mappedArray[j] = charValue;
}
}
}
var resultString = mappedArray.join('');
return resultString;
}
function get(x) {
var a = unsbox(x);
return hexXor(a, '3000176000856006061501533003690027800375');
}
console.log(get('60E8467608F12C5CF80B372A5CCEF1E3383375C0'));
PHP 代码
function hexXor($str, $key) {
$result = '';
for ($i = 0; $i < strlen($str) && $i < strlen($key); $i += 2) {
$substr1 = substr($str, $i, 2);
$substr2 = substr($key, $i, 2);
$num1 = hexdec($substr1);
$num2 = hexdec($substr2);
$xorResult = $num1 ^ $num2;
$hexResult = dechex($xorResult);
if (strlen($hexResult) == 1) {
$hexResult = '0' . $hexResult;
}
$result .= $hexResult;
}
return $result;
}
function unsbox($str) {
$mapping = [0xf, 0x23, 0x1d, 0x18, 0x21, 0x10, 0x1, 0x26, 0xa, 0x9, 0x13, 0x1f, 0x28, 0x1b, 0x16, 0x17, 0x19, 0xd, 0x6, 0xb, 0x27, 0x12, 0x14, 0x8, 0xe, 0x15, 0x20, 0x1a, 0x2, 0x1e, 0x7, 0x4, 0x11, 0x5, 0x3, 0x1c, 0x22, 0x25, 0xc, 0x24];
$mappedArr = array_fill(0, count($mapping), '');
$result = '';
for ($i = 0; $i < strlen($str); $i++) {
$char = $str[$i];
foreach ($mapping as $index => $value) {
if ($value == $i + 1) {
$mappedArr[$index] = $char;
}
}
}
$result = implode('', $mappedArr);
return $result;
}
function get($x) {
$a = unsbox($x);
return hexXor($a, '3000176000856006061501533003690027800375');
}
echo get('60E8467608F12C5CF80B372A5CCEF1E3383375C0');