A small CLI that removes password protection from a PDF using pikepdf. Supports two modes:
password: a single password attempt.brute-date: brute-force a password of the formPREFIX + formatted-dateacross a date range, for the case where you know the password is built from a known pattern (e.g.OLIV2403for someone's birthday) but you have forgotten the exact day.
Uses uv.
uv sync# Single password
uv run python unlock_pdf.py locked.pdf password mypassword
# Custom output path
uv run python unlock_pdf.py locked.pdf -o decrypted.pdf password mypassword
# Brute-force OLIV + ddmm across all of 2024
uv run python unlock_pdf.py locked.pdf brute-date --prefix OLIV --start 2024-01-01 --end 2024-12-31
# Different date format. e.g. yyyymmdd, no prefix
uv run python unlock_pdf.py locked.pdf brute-date --start 1990-01-01 --end 2000-12-31 --format "%Y%m%d"The --format argument is a Python strftime format string. %d%m is 2403, %Y%m%d is 19900124, etc.
Brute-force runs serially and tries one password per day, so a 365-day window finishes in well under a minute on a small PDF. For larger keyspaces this script is the wrong tool. Use a dedicated cracker.