Created
October 25, 2011 08:33
-
-
Save troufster/1311853 to your computer and use it in GitHub Desktop.
valtech problem 9 solution
This file contains hidden or 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'); | |
var vals = ["ab", "cd", "ef", "gh", "ij", "kl", "mn", "op", "qr", "st", "uv", "xy", "z0", "12", "34"]; | |
var hex_md5 = function(data) { | |
return crypto.createHash('md5').update(data).digest("hex"); | |
}; | |
var try = function() { | |
//2^15 | |
var max = 32768; | |
while(max--) { | |
var variant = max.toString(2); | |
//Pad binary string if shorter than 15 bits | |
if(variant.length < 15) { | |
var diff = 15 -variant.length; | |
for(var i =0; i < diff; i++) { | |
variant = '0' + variant; | |
} | |
} | |
var len = variant.length; | |
var pass = ''; | |
for (var i = 0; i < len; i++) { | |
var bit = variant.charAt(i); | |
pass += bit == 1 ? vals[i] : 'aa'; | |
} | |
var hash = hex_md5(pass); | |
//console.log(variant + ' ' + pass + ' ' + hash); | |
if (hash == '05eba37714e48265bb8a289341128f22') { | |
console.log("Password found: " + pass ); | |
break; | |
} | |
} | |
}; | |
try(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment