帮助将小Python代码转换为PHP

时间:2010-01-15 03:43:46

标签: php python

请将python代码转换为php语法需要一些帮助 该代码用于使用alpha编码生成字母数字代码

代码:

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"  

任何帮助都会非常感激......

2 个答案:

答案 0 :(得分:4)

我会帮助你一点点。对于其余部分,请阅读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++)
<<                                     <<

其余部分,如+ =,==等,在两种语言中几乎相同。

答案 1 :(得分:0)

  

其余的,如+ =,==等   2中几乎相同   语言。

小心;在PHP中,字符串连接是使用.=而不是+=完成的。如果您尝试使用+= PHP将尝试以数学方式评估表达式(可能返回null)并且您将试图找出您的脚本有什么问题。