这是是JS的, 我想转成PHP的,
不懂PHP,谢谢呀
function Getkey(key, sc) {
return (key * 0x0063 + sc) % 0x100
}
function Apple(str) {
var len = str.length / 2;
var i = 1;
var tmp = '';
var key = eval("0x" + str.charAt(0) + str.charAt(1));
while (i < len) {
istr = eval("0x" + str.charAt(i * 2) + str.charAt(i * 2 + 1));
istr = key ^ istr;
if (istr == 2) {
i = i + 1;
key = Getkey(key, istr);
istr = eval("0x" + str.charAt(i * 2) + str.charAt(i * 2 + 1));
istr = key ^ istr;
jstr = istr;
i = i + 1;
key = Getkey(key, istr);
istr = eval("0x" + str.charAt(i * 2) + str.charAt(i * 2 + 1));
istr = key ^ istr;
jstr = jstr * 256 + istr;
tmp = tmp + String.fromCharCode(jstr)
} else tmp = tmp + String.fromCharCode(istr);
i = i + 1;
key = Getkey(key, istr)
}
return tmp
}
------解决方案--------------------
- PHP code
echo Apple("123123");//输出 "#:" 对吗?function Getkey($key, $sc){ return ($key * 0x0063 + $sc) % 0x100;}function Apple($str) { $len = mb_strlen($str, "GBK") / 2; $i = 1; $tmp = ''; $key = "0x" . $str{0} . $str{1} + 0; while ($i < $len){ $istr = "0x" . $str{$i * 2} . $str{$i * 2 + 1} + 0; $istr = $key ^ $istr; if ($istr == 2) { $i = $i + 1; $key = Getkey($key, $istr); $istr = "0x" . $str{$i * 2} . $str{$i * 2 + 1} + 0; $istr = $key ^ $istr; $jstr = $istr; $i = $i + 1; $key = Getkey($key, $istr); $istr = "0x" . $str{$i * 2} . $str{$i * 2 + 1} + 0; $istr = $key ^ $istr; $jstr = $jstr * 256 + $istr; $tmp = $tmp . chr($jstr); } else $tmp = $tmp . chr($istr); $i = $i + 1; $key = Getkey($key, $istr); } return $tmp;}
------解决方案--------------------
楼上厉害!
------解决方案--------------------