diff --git a/README.md b/README.md index ad7189c..fe2df74 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,12 @@ Files are: (1) Bank account statement (2) Few certificates where the first four letters are first four letters of your name along with your date and month of birthdate. + +- This code uses MPI to perform coordinated parallel guesses using multiple processors. +- This is ideal for guessing long passwords with brute force using supercomputers. + +Use Python (tested with version `3.10`) to run this +- [Optional] Create and use virtual environment: `python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt` +- Run the code: `time mpiexec -n python guess_pdfPass-parallel.py` + +> Dependency: qpdf (https://github.com/qpdf/qpdf), tested with version 11.9.1. Make sure `qpdf` and its libraries are added to `PATH` and `LD_LIBRARY_PATH` respectively. diff --git a/guess_pdfPass-parallel.py b/guess_pdfPass-parallel.py new file mode 100644 index 0000000..4b05f50 --- /dev/null +++ b/guess_pdfPass-parallel.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +""" +Created on Sun Jun 16 21:57:11 2024 +@author: alankar +Usage: time mpiexec -n python guess_pdfPass-parallel.py +Dependency: qpdf (https://github.com/qpdf/qpdf), tested with version 11.9.1 +Note: Make sure qpdf and its libraries are added to PATH and LD_LIBRARY_PATH respectively +Thanks: Samriddhi Sankar Maity +- This code uses MPI to perform coordinated parallel guesses using multiple processors. +- This is ideal for guessing long passwords with brute force using supercomputers +""" + +import subprocess as sp +from mpi4py import MPI +from itertools import product + +## start parallel programming ---------------------------------------- # +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + +verbose = False + +initial_known_pass = "9899" + +input_file = "sample.pdf" +output_file = "sample-decrypt.pdf" + +# trying to guess unknown 6 digits +tries = list(product(range(10),range(10),range(10),range(10),range(10),range(10))) + +for i in range(rank, len(tries), size): + guess_pass = "".join(str(x) for x in tries[i]) + text = sp.getoutput(f'qpdf -password="{initial_known_pass}{guess_pass}" -decrypt {input_file} {output_file}') + if verbose: + print(f"{initial_known_pass}{guess_pass}: {text}", flush=True) + if "invalid password" not in text: + print(f"Password found: {initial_known_pass}{guess_pass}", flush=True) + comm.Abort() +print("Set settings failed to guess the password.") diff --git a/pdf_passwd.sh b/pdf_passwd.sh deleted file mode 100644 index ac763ec..0000000 --- a/pdf_passwd.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -name="PASS" # First 4 letters of your name -FILEIN="sample_out.pdf" # Input file name -FILEOUT="sample_open.pdf" # Output file name - -for mm in $(seq -f "%02g" 1 12) -do - for dd in $(seq -f "%02g" 1 31) - do - qpdf -password="${name}"$dd$mm -decrypt $FILEIN $FILEOUT - if test -f "$FILEOUT"; then - echo File Opened! - echo Password "${name}"$dd$mm - break - fi - done -done -echo all done - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..386e96a --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +mpi4py==3.1.5 ; python_version >= "3.10" and python_version < "4.0"