Created
February 16, 2014 20:21
-
-
Save riston/9040092 to your computer and use it in GitHub Desktop.
Hash finder for hash challange http://www.h11e.com/
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
var crypto = require('crypto'), | |
cuid = require('cuid'), | |
string, | |
zeros = 0, | |
currentHash = '', | |
currentZeros = 0, | |
hash; | |
function findZeros(hash) { | |
var chars = hash.split(''), | |
zeros = 0, | |
i; | |
for (i = 0; i < chars.length; i++) { | |
if (chars[i] === '0') { | |
zeros++; | |
} else { | |
break; | |
} | |
} | |
return zeros; | |
} | |
/** | |
* Why you use interval here why not while (true) ? | |
* Because the computer I use is not meant for this mainly | |
* | |
* You know that in node you got one thread ? | |
* Yes you can use cluster module for creating something fancier for this | |
* | |
* @return {Number} interval id | |
*/ | |
var id = setInterval(function () { | |
string = cuid(); | |
hash = crypto.createHash('sha512').update(string).digest('hex'); | |
currentZeros = findZeros(hash); | |
if (currentZeros > zeros) { | |
currentHash = hash; | |
zeros = currentZeros; | |
console.log("Better hash found " + hash + " - " + string); | |
} | |
}, 20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment