Function from C/PHP to Python

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Aug 7 00:01:59 EDT 2008


On Wed, 06 Aug 2008 20:15:11 -0700, Grom wrote:

> Hello everyone :)
> I have one problem with that function in C
...
> Can someone help me to rewrite it to python?
> 
> There is the same function, in PHP:
...
> Please... its very important to me

I don't know C or PHP. But since it's important, and because you said 
please, let me try:


def calc_passcode(password):
    magic1 = 0x50305735
    magic2 = 0x12345671
    sum = 7
    for i in range(len(password)):
        z = ord(password[i])
        if z == 32 or z == 9:
            continue
        magic1 = magic1 ^ ((((magic1 & 0x3f) + sum) * z) + (magic1 << 8))
        magic2 = magic2 + ((magic2 << 8) ^ magic1)
        sum += z
        magic1 = magic1 & 0x7fffffff
        magic2 = magic2 & 0x7fffffff
    return '%08x%08x' % (magic1, magic2)



-- 
Steven



More information about the Python-list mailing list