From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chapter13PracBruteForcePDF.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Chapter13PracBruteForcePDF.py (limited to 'Chapter13PracBruteForcePDF.py') diff --git a/Chapter13PracBruteForcePDF.py b/Chapter13PracBruteForcePDF.py new file mode 100644 index 0000000..14af439 --- /dev/null +++ b/Chapter13PracBruteForcePDF.py @@ -0,0 +1,32 @@ +#! /usr/bin/env python3 + +# Chapter 13 Practice Brute-Force PDF Password Breaker +# USAGE: Change the pdfFile varible below and run the script to try 44,000 English words +# from the dictionary.txt file to decrypt the encrypted PDF. + +import PyPDF2 + +pdfFile = open('bruteForce.pdf', 'rb') #Change this file name and location +pdfReader = PyPDF2.PdfFileReader(pdfFile) + +dictionaryFile = open('dictionary.txt') +passwordList = dictionaryFile.readlines() + +for word in range(len(passwordList)): + passWord = passwordList[word].strip() + passWorkedUpper = pdfReader.decrypt(passWord.upper()) + if passWorkedUpper == 1: + print('The password is: ' + passWord.upper()) + break + else: + print(passWord.upper() + ' did NOT work...') + passWorkedLower = pdfReader.decrypt(passWord.lower()) + if passWorkedLower == 1: + print('The password is: ' + passWord.lower()) + break + else: + print(passWord.lower() + ' did NOT work...') + +dictionaryFile.close() +pdfFile.close() + -- cgit