Created
April 23, 2019 13:02
-
-
Save thiagomata/5668e71b5693319356cbb0ee85d4f58b to your computer and use it in GitHub Desktop.
Playing around creating combinations from number based on dic
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
const exec = require('child_process').exec; | |
var letters = " abcdefghijklmnopqrstuvxz".split(""); | |
var args = process.argv.slice(2); | |
function number_to_word(number) { | |
let result = ""; | |
while (number > 0 ) { | |
let pos = number % letters.length; | |
let char = letters[ pos ]; | |
number -= pos; | |
number /= letters.length; | |
result = char + result; | |
} | |
return result.trim(); | |
} | |
function test_word_thread(current_word,thread=0,call_next=false){ | |
const word = current_word + thread; | |
const password = number_to_word(word); | |
if ( password.indexOf(" ") > -1 ) { | |
if( call_next ) { | |
test_word(word,thread); | |
} | |
return; | |
} | |
const child = exec(`qpdf --decrypt --password=${password} doc.pdf decrypted-filename.pdf`, | |
(error, stdout, stderr) => { | |
if (error == null ) { | |
console.log(`password: ${password}`); | |
process.exit(); | |
} else { | |
if( word % 1000 == 0 ) { | |
console.log(`current_word = ${word} `,password) | |
} | |
if( call_next ) { | |
test_word(word,thread); | |
} | |
} | |
}); | |
} | |
function test_word(current_word,total_threads=8) { | |
for(current_thread = 1; current_thread <= total_threads; current_thread++ ) { | |
test_word_thread(current_word,current_thread,total_threads==current_thread); | |
} | |
} | |
test_word(1 * args[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment