JS code to PHP thanks. this is JS. I want to convert it to PHP. I don't know PHP. thank you! functionGetkey (key, SC) {return (key * 0x0063 + SC) % 0x100} functionApple (str) {varlenstr. leng2; vari1; vartmp; var JS code to PHP thanks
This is JavaScript. I want to convert it to PHP,
PHP is not understood. thank you.
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
}
------ Solution --------------------
PHP code
Echo Apple ("123123"); // output "#:" right? 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 ;}
------ Solution --------------------
Upstairs!
------ Solution --------------------
Discussion
For more information, add "$" in front of the variable.