Created
February 18, 2014 07:34
-
-
Save drslump/9066219 to your computer and use it in GitHub Desktop.
djb2 hash implementation
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
def djb2(data as string): | |
""" Computes a 32bit hash using the djb2 algorithm """ | |
payload = System.Text.Encoding.ASCII.GetBytes(data) | |
result as uint = 5381 | |
for ch in payload: | |
unchecked: | |
result = result * 33 + ch | |
return result & 0xffffffff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment