def ap_hash(key): hash_value = 0xAAAAAAAA for i in range(len(key)): if (i & 1) == 0: hash_value ^= ((hash_value << 7) ^ ord(key[i]) * (hash_value >> 3)) else: hash_value ^= (~((hash_value << 11) + ord(key[i]) ^ (hash_value >> 5))) return hash_value