Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# https://www.thepythoncode.com/article/crack-pdf-file-password-in-python
import pikepdf
from tqdm import tqdm
# load password list
passwords = []
for y in range(70, 99):
for m in range(1, 12):
for d in range(1, 31):
passwords.append(str(y) + ('0' + str(m))[-2:] + ('0' + str(d))[-2:])
# iterate over passwords
for password in tqdm(passwords, "Decrypting PDF"):
try:
# open PDF file
with pikepdf.open("../Downloads/1.pdf", password=password) as pdf:
# Password decrypted successfully, break out of the loop
print("[+] Password found:", password)
break
except pikepdf._qpdf.PasswordError as e:
# wrong password, just continue in the loop
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment