Code for How to Crack PDF Files in Python Tutorial

View on Github

import pikepdf
from tqdm import tqdm

# load password list
passwords = [ line.strip() for line in open("wordlist.txt") ]

# iterate over passwords
for password in tqdm(passwords, "Decrypting PDF"):
        # open PDF file
        with"foo-protected.pdf", password=password) as pdf:
            # Password decrypted successfully, break out of the loop
            print("[+] Password found:", password)
    except pikepdf._core.PasswordError as e:
        # wrong password, just continue in the loop