-
-
Save SolomonSklash/0f6dd6e7f25045f5d394b721148bdbc6 to your computer and use it in GitHub Desktop.
DJB2 Hash in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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