Created
January 20, 2014 19:24
-
-
Save freekrai/8527310 to your computer and use it in GitHub Desktop.
DJB2 Hash in PHP
This file contains 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
<?php | |
function hash_djb2($str){ | |
$hash = 5381; | |
$length = strlen($str); | |
for($i = 0; $i < $length; $i++) { | |
$hash = ( ($hash << 5) + $hash ) + $str[$i]; | |
} | |
return ($hash & 0xFFFFFFFF); | |
} | |
// how to call the function: | |
$hash = hash_djb2( "bacon" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment