Last active
January 11, 2017 18:56
-
-
Save toobulkeh/c59e2ad178a9d01df99f13f7aa667f8b to your computer and use it in GitHub Desktop.
trelloreversehash
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
//https://trello.com/jobs/details?gh_jid=480058 | |
window.letters = "acdegilmnoprstuw"; | |
function hash(s) { | |
var h = 7; | |
for(var i = 0; i < s.length; i++) { | |
h = h * 37 + letters.indexOf(s[i]); | |
} | |
return h; | |
} | |
//this is O(letters.length ^ left). It'll crash your shit. | |
function brutehash(s, left) { | |
if(left === 0) { | |
if(hash(s) === 680131659347) { | |
console.log('found it: ' + s); | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
for(var i = 0; i < letters.length; i++) { | |
if(brutehash(s + letters[i], left-1)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
//reversehash(930846109532517, '') = 'found: lawnmower' | |
//reversehash(680131659347, '') = 'found: leepadg' | |
function reversehash(num, result) { | |
for(var i = 0; i < letters.length; i++) { | |
rev = (num - i) / 37; | |
//console.log('trying '+letters[i]+', rev: '+rev); | |
if(rev % 1 === 0) { | |
result = letters[i] + result; | |
if(rev === 7) { | |
console.log('found: '+result); | |
return true; | |
} else { | |
if(reversehash(rev, result)) { | |
return true; | |
} | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment