def mysqlPass(aStr): nr = 1345345333 add = 7 nr2 = 0x12345671 for each in aStr: if each == ' ' or each == '\t': continue tmp = ord(each) nr ^= (((nr & 63) + add) * tmp) + (nr << 8) nr2 += (nr2 << 8) ^ nr add += tmp result1 = nr & ((1 << 31) -1) result2 = nr2 & ((1 << 31) -1) return "%08x%08x" % (result1,result2) if __name__=="__main__": print mysqlPass("testing")