Last active
August 29, 2015 14:27
-
-
Save matsilva/0348626b975b49b56d55 to your computer and use it in GitHub Desktop.
Trello decode hash solution
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
function hash (s){ | |
var h = 7 | |
var letters = 'acdegilmnoprstuw' | |
for(var i = 0; i < s.length; i++){ | |
console.log(h + ' ' + s[i] + ' ' + letters.indexOf(s[i])) | |
h = (h*37 + letters.indexOf(s[i])) | |
} | |
return h | |
} | |
function decodeHash (hash){ | |
var h = 7 | |
var letters = 'acdegilmnoprstuw' | |
var hashstring = '' | |
var reduced = hash | |
while(reduced != 7 ){ | |
for (var i= 0; i < letters.length; i++){ | |
var hashReduced = (reduced i)/37 | |
if(hashReduced % 1 === 0 ){ | |
hashstring += letters[i] | |
//lastSolvedHash | |
reduced = hashReduced | |
//console.log(reduced + ' ' + letters[i] + ' ' + i) | |
break; | |
} | |
} | |
console.log(reduced) | |
} | |
return console.log(hashstring.split('').reverse().join('')) | |
} | |
decodeHash(956446786872726) | |
// hash('leepadg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution will decode the hash... or crash your machine ;)