summaryrefslogtreecommitdiff
path: root/Chapter13PracBruteForcePDF.py
diff options
context:
space:
mode:
authormlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
committermlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
commit75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch)
tree84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chapter13PracBruteForcePDF.py
initial commit for archivingHEADmain
Diffstat (limited to 'Chapter13PracBruteForcePDF.py')
-rw-r--r--Chapter13PracBruteForcePDF.py32
1 files changed, 32 insertions, 0 deletions
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()
+