Created
February 20, 2016 10:09
-
-
Save r03ert0/bf1aa22526bf9290bec1 to your computer and use it in GitHub Desktop.
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
/* | |
Given the string str, produce a shorter random hash. | |
Different strings could produce the same hash, although | |
this is unlikely. | |
*/ | |
function hash(str) { | |
var i,v0,v1,abc="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
v0=0; | |
for(i=0;i<str.length;i++) { | |
v1=str.charCodeAt(i); | |
v0+=v0+v0^v1; | |
} | |
var sz=abc.length,v,res=""; | |
for(i=0;i<5;i++) { | |
v1=parseInt(v0/sz); | |
v=Math.abs(v0-v1*sz); | |
res+=abc[v]; | |
v0=v1; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment