Created
December 14, 2016 18:01
-
-
Save superchris/4291b44cdfa8d9becbbbc023017e8a32 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
var md5 = require('md5'); | |
var salt = "jlmsuwbz"; | |
var index = 0; | |
var keys = 0; | |
const THREE_MATCH = /(.)\1\1/ | |
function santaHash(input, index) { | |
return md5(input+index); | |
}; | |
function hasThreeOfAKind(hash) { | |
arr = hash.match(THREE_MATCH) | |
return arr == null ? false : arr[1] | |
} | |
function hasFiveOfAKind(hash, character) { | |
return hash.indexOf(character + character + character + character + character) > -1 | |
} | |
while (keys < 64) { | |
var hash = santaHash(salt, index); | |
var matchingCharacter = hasThreeOfAKind(hash); | |
if(matchingCharacter) { | |
for (var i = 1; i <= 1000; i++) { | |
var newHash = santaHash(salt, i + index); | |
if (hasFiveOfAKind(newHash, matchingCharacter)) { | |
keys++; | |
break; | |
} | |
} | |
} | |
if (keys === 64) { | |
break; | |
} | |
index++; | |
} | |
console.log(index) | |
while(!found){ | |
var hash = santaHash(salt, index); | |
var matchingCharacter = hasThreeOfAKind(hash); | |
if(matchingCharacter) { | |
matches[matchingCharacter] = index; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment