views:

149

answers:

3

Hello,

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 ...

+3  A: 

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.

ghostdog74
A: 

Thanks a lot ghostdog74, i got it now and going to resume the rest of the job in php

really appreciated and stackoverflow.com is the right place for helping everybody

Thanks again Sir :)

Sp1der_Net
Use the comments of a reply for thanking someone. This isn't a forum.
Matt Huggins
A: 

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.

LeguRi
Like Sp1der_Net's "answer", the above "answer" should also be a comment. One very good reason is that when you comments on someone's answer, that person will get a notification on every SO page that their answer has received a comment.
outis
Good call; Thanks. I'm new here, so I appreciate the guidance.
LeguRi
@outis actually, for the person get notified an answer is **currently** much better than a comment. Both email and RSS focus on showing only answers, and they give no comments at all.
Cawas
@Cawas: "Better", in this case, isn't precise enough a term. E-mail notifications and subscribing to the RSS feed of questions require action on part of a user (personally, I don't use either for questions I answer). The response notification when a logged-in user views an SO page, however, requires no action. As a consequence, you could just as easily say the latter is "better".
outis
outis
@outis yes, answers should be answers, and comments should be comments. Not arguing that. I'm just saying that if you want to get in touch with someone, and that person get notified through SO (a lot of users don't provide another method on their profile), answering a question from them will grant better results in general. But it's surely much more appropriate to use comments.
Cawas