Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DJB2 Hash in Python
#!/usr/bin/env python
# encoding: utf-8
def hash_djb2(s):
hash = 5381
for x in s:
hash = (( hash << 5) + hash) + ord(x)
return hash & 0xFFFFFFFF
hex(hash_djb2(u'hello world, 世界')) # '0xa6bd702fL'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.