Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Created January 6, 2020 12:49
Show Gist options
  • Select an option

  • Save LevitatingBusinessMan/96c9b0e8f07d6ca6ce96d16c20458af7 to your computer and use it in GitHub Desktop.

Select an option

Save LevitatingBusinessMan/96c9b0e8f07d6ca6ce96d16c20458af7 to your computer and use it in GitHub Desktop.
Alechash (md5 cracker)
const readline = require('readline')
const crypto = require("crypto")
//require('draftlog').into(console)
//config
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const maxLength = 10;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let found = false
const inputIsPassword = process.argv.includes("-p")
let hash
let updateDraftlog
let start
rl.question(inputIsPassword ? "Password:\n" : "Hash:\n", answer => {
rl.close()
if (inputIsPassword) {
hash = md5(answer)
}
else hash = answer
updateDraftlog = console.draft("")
start = new Date()
while (!found) cycle()
});
const indeces = [0];
function cycle() {
if (indeces.length > maxLength)
return
let string = ""
for (let i = 0; i < indeces.length; i++) {
string += chars[indeces[i]]
}
const hashedString = md5(string)
//updateDraftlog(hashedString)
if (hashedString == hash)
return finish(string)
let lastElementIndex = indeces.length - 1;
increase(lastElementIndex);
function increase (index) {
//Room to increase
if (indeces[index] < chars.length - 1)
indeces[index]++;
//No room to increase, increase element before last
else {
//overflow it
indeces[index] = 0;
//Already at start, add new character
if (index == 0)
indeces.unshift(0);
//Otherwise increase character before index
else increase(index-1)
}
}
}
function finish(pass) {
console.log(`Found ${pass} after ${((new Date() - start)/1000).toFixed(2)}s`)
found = true
}
function md5(input) {
return crypto.createHash('md5').update(input).digest("hex")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment