Brute Force Discrete Homework
A script to crack password-protected homework PDFs in under 1 second.
Python, Bash, qpdf
One of my classes locked the current week’s homework pdf with a password. The password could be found in the solutions to the previous week’s homework. Instead of reading the solutions carefully, I wrote a script to try to brute force the password as fast as possible. I got it to brute force the pdf in under 1 second.
The first step is to turn the pdf into a text file, so it can be parsed.
I then use two facts about the password to quickly discard most of the file:
- It is so strange that it occurs only once
- It is inconspicuously in the middle of the sentence, and thus is all lowercase
I get the words of frequency 1 with a hash map, and use a lambda function to check if all of the characters are lowercase. These words are output as a text file.
The bash script uses qpdf and loops through this text file of possible words. If an output file is successfully generated, the loop terminates and the PDF is cracked.