Skip to content

Instantly share code, notes, and snippets.

@sriprasanna
Created March 11, 2015 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriprasanna/2dccf3623d4da9e0cef7 to your computer and use it in GitHub Desktop.
Save sriprasanna/2dccf3623d4da9e0cef7 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Trello Test</title>
<style>
li.pass{
color:green;
}
li.fail{
color:red;
}
</style>
<script type="text/javascript">
var letters = "acdegilmnoprstuw";
function hash(string) {
var computed_hash = 7;
for (var i = 0; i < string.length; i++) {
computed_hash = computed_hash * 37 + letters.indexOf(string[i]);
}
return computed_hash;
}
function dehash(computed_hash){
if (parseInt(computed_hash) == 7) { return ""; }
return dehash(computed_hash / 37) + letters[parseInt(computed_hash % 37)];
}
</script>
<script>
function assert(value,desc){
var li = document.createElement("li");
li.className = value? "pass": "fail";
li.appendChild(document.createTextNode(desc));
document.getElementById("results").appendChild(li);
}
window.onload = function(){
assert(hash("leepadg") == 680131659347, "Test hashing function - leepadg");
assert(dehash(680131659347, 7) == "leepadg", "Test dehashing function - 680131659347");
assert(hash("ac") == 9584, "Test hashing function - ac");
assert(dehash(9584, 2) == "ac", "Test dehashing function - 9584");
};
</script>
</head>
<body>
<ul id="results"></ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment