Skip to content

Instantly share code, notes, and snippets.

@thiagomata
Created April 23, 2019 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomata/5668e71b5693319356cbb0ee85d4f58b to your computer and use it in GitHub Desktop.
Save thiagomata/5668e71b5693319356cbb0ee85d4f58b to your computer and use it in GitHub Desktop.
Playing around creating combinations from number based on dic
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