PDF Brute Force Cracker
import itertools
import string
from PyPDF2 import PdfReader
def brute_force_pdf(pdf_path, max_length=8):
characters = string.ascii_lowercase + string.digits
# You can add digits, symbols, etc.
print(f"Starting brute force on {pdf_path}")
# Try only passwords of exact length (e.g., 3)
length = max_length
for guess_tuple in itertools.product(characters, repeat=length):
guess = ''.join(guess_tuple)
try:
reader = PdfReader(pdf_path)
if reader.decrypt(guess) == 1:
print(f"✅ Password cracked! The password is: {guess}")
return guess
except Exception as e:
pass # Ignore errors, continue guessing
print(f"Trying password: {guess}")
print("❌ Password not found within given max length.")
return None
# Example usage:
pdf_file = "your.pdf" # Replace with your actual file path
brute_force_pdf(pdf_file, max_length=8)
Code output
Trying password: aaaaarxp
Trying password: aaaaarxq
Trying password: aaaaarxr
Trying password: aaaaarxs
Trying password: aaaaarxt