Skip to content

Instantly share code, notes, and snippets.

@hyeonseok
Created July 2, 2021 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyeonseok/f1c49af76a7c013c5fbb8d26f82e82f6 to your computer and use it in GitHub Desktop.
Save hyeonseok/f1c49af76a7c013c5fbb8d26f82e82f6 to your computer and use it in GitHub Desktop.
# 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