Help in Converting Small Python Code to PHP
please i need some help in converting a python code to a php syntax the code is for generating an alphanumeric code using alpha encoding
the code :
def mkcpl(x):
x = ord(x)
set="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
for c in set:
d = ord(c)^x
if chr(d) in set:
return 0,c,chr(d)
if chr(0xff^d) in set:
return 1,c,chr(0xff^d)
raise Exception,"No encoding found for %#02x"%x
def mkalphadecryptloader(shcode):
s="hAAAAX5AAAAHPPPPPPPPa"
shcode=list(shcode)
shcode.reverse()
shcode = "".join(shcode)
shcode += "\x90"*((-len(shcode))%4)
for b in range(len(shcode)/4):
T,C,D = 0,"",""
for i in range(4):
t,c,d = mkcpl(shcode[4*b+i])
T += t << i
C = c+C
D = d+D
s += "h%sX5%sP" % (C,D)
if T > 0:
s += "TY"
T = (2*T^T)%16
开发者_开发技巧 for i in range(4):
if T & 1:
s += "19"
T >>= 1
if T == 0:
break
s += "I"
return s+"\xff\xe4"
any help would be really appreciated ...
i will help you a little. For the rest of it, please read up on the documentation.
function mkcpl($x){
$x=ord($x);
$set="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$set=str_split($set);
foreach($set as $c){
$d=ord($c)^$x;
if( in_array( chr($d) ,$set ) ){
return array(0,$c,chr($d));
}
if ( in_array( chr(0xff^d) ,$set ) ){
return array(0,$c,chr(0xff^$d));
}
}
}
function mkalphadecryptloader($shcode){
$s="hAAAAX5AAAAHPPPPPPPPa";
# you could use strrev()
$shcode=str_split($shcode);
$shcode=array_reverse($shcode);
$shcode=implode("",$shcode);
# continue on... read the documentation
}
print_r(mkcpl("A"));
mkalphadecryptloader("abc");
Python: PHP
len() - length of string/array. strlen(),count()
range() - generate range of numbers for($i=0;$i<=number;$i++)
<< <<
the rest of them, like +=, == etc are pretty much the same across the 2 languages.
the rest of them, like +=, == etc are pretty much the same across the 2 languages.
Careful; in PHP string concatenation is accomplished using .=
not +=
. If you try to use +=
PHP will try to evaluate the expression mathematically (probably returning a null) and you'll be pulling your hair out trying to figure out what's wrong with your script.
精彩评论