How to Crack PDF Passwords Using a Dictionary Attack Method
A dictionary attack against a password-protected PDF tests a finite set of candidate passwords against the document’s encryption handler. For a file you created or have explicit authority to recover, a tiny, controlled test can show the principle without gathering leaked passwords, uploading a confidential document to an online service, or attempting to defeat someone else’s access controls. The outcome is limited: if the correct password is absent from the tested set, the test cannot recover it.
This is a practical laboratory walkthrough using a synthetic PDF whose password is chosen in advance. It is deliberately different from a beginner’s guide to encrypted PDF recovery decisions, which explains when password testing is warranted at all. Here the job is to create a harmless example, run three documented guesses locally, interpret the result, and understand why real recovery often cannot be promised.
A PDF may require a password before it can be opened, or it may open normally but restrict printing, copying or modification in compliant readers. Those are not identical problems. The PDF specification has historically distinguished user and owner passwords, and the qpdf encryption documentation explains how both relate to an encryption key and the document’s permission flags. A file that opens without a password is not evidence that its contents are unencrypted, nor does a permissions warning automatically justify trying to discover somebody’s document-opening password.
Before using recovery software, confirm that the file belongs to you or is within an authorized organizational investigation. Keep the original byte-for-byte, record its source and hash if it is evidence, and work on a verified copy. Check whether the creator can supply another copy, a password manager holds the credential, or an approved backup preserves the readable source. Those options usually produce a better result than guessing. If a file is legally protected or contains third-party confidential data, obtain the necessary authorization before inspecting it.
It also matters which PDF encryption revision and algorithm are in use. Older formats and modern AES-protected PDFs impose different computational costs; a successful test with an intentionally short laboratory password is not a benchmark for a modern document with a long, randomly generated passphrase. Never claim that a dictionary attack can simply break AES encryption. It normally tests guesses for the password used to unlock the encryption key.
The sample uses the open-source pypdf library and its documented encryption and decryption interfaces. The example creates an empty one-page PDF; it does not consume or modify an external document. Work in a folder you control, in a Python environment where pypdf and its supported AES cryptography dependency are installed. The example password is intentionally weak so the test is easy to understand. It must never be used as a real security credential.
from pypdf import PdfWriter
writer = PdfWriter()
writer.add_blank_page(width=612, height=792)
writer.encrypt(
user_password="orchard",
owner_password="private",
algorithm="AES-256",
)
writer.write("lab-document.pdf")
The resulting document is a controlled test artifact. The pypdf encryption documentation shows how its reader and writer work with password-protected documents and why modern AES settings are preferable to obsolete RC4 defaults. This library example is meant to explain an API, not to certify a PDF against every threat. Protect the toy file from confusion with real evidence by labeling the laboratory directory and keeping production documents elsewhere.
In the next example, the dictionary has just three ordinary, fictional words. The code reopens the same laboratory PDF for each attempt so that each password check starts from a fresh reader. The decrypt method returns a status that indicates whether the supplied password unlocked the file; no content is extracted or copied. The third candidate is never tested because the second one succeeds.
from pypdf import PdfReader
candidates = ["apricot", "orchard", "cedar"]
for candidate in candidates:
reader = PdfReader("lab-document.pdf")
if reader.decrypt(candidate):
print("Match found in the local test list")
break
else:
print("No match in this three-entry list")
With the example file from the previous section, the expected output is Match found in the local test list. This only demonstrates that the correct password was deliberately included in the list. Change the three words so that none equals the password, and the script reaches the no-match output. That result does not say the PDF was corrupted, its encryption was stronger, or that the password is unknowable; it merely says the short set of attempted candidates did not work.
Do not generalize from this exercise to broad password enumeration, leaked wordlists, parallel cracking infrastructure or remote login services. A locally owned PDF is not an online account. The security boundary, authorization, processing cost and observable failure modes are different, and uncontrolled expansion can expose sensitive data or produce an unacceptable investigation process. This lesson deliberately does not build an automated mass-guessing tool.
In a legitimate recovery situation, a verified correct password permits an authorized reader to access the document, but it is not an instruction to silently strip protections from a signed or legally controlled record. An investigator should preserve the original encrypted file and its associated evidence record. If a decrypted working copy is permitted, identify it explicitly as a derivative, record who created it, retain any required audit logs, and review the consequences for signatures, access restrictions and retention policy.
When an attempt fails, first verify that the file is a valid PDF and that its password requirements were interpreted correctly. The qpdf documentation covers inspection options and distinguishes a file that is not encrypted from one that requires a password. Repeated attempts may not be the right diagnostic response: an incorrect file path, unsupported encryption variant, a damaged file or a forgotten difference between user and owner passwords can produce confusion unrelated to dictionary size.
For personal recovery, keep the working file on a trusted device, avoid public conversion websites for confidential records, and do not paste candidate passwords into shared logs. For enterprise work, require written authorization specifying the exact documents, custodians, retention boundaries and how the output will be protected. If the correct password cannot be recovered by authorized means, request a replacement from the owner or source system rather than implying that password-guessing software must eventually succeed.
A dictionary works only when there is overlap between the candidate set and the chosen password. Common words, predictable alterations and reused passwords may be guessable; independently generated, sufficiently long passphrases are substantially less likely to appear in a small list. The effective difficulty also depends on how the PDF format derives and checks encryption keys. Two files with different cryptographic parameters do not necessarily take the same time to test a password.
Do not present a fixed number of guesses per second as though it applies to all PDF files. Benchmarks vary with the format, algorithm, hardware and software implementation. Even a theoretical search-space estimate depends on assumptions about how the password was selected. The important result of the toy example is logical rather than numerical: membership in the dictionary is the decisive property, and absence from that dictionary produces a legitimate failure.
Organizations can reduce future recovery disputes by using managed password vaults, accountable document ownership, approved archival copies and documented key custody. They should also review whether a password-protected PDF is the appropriate way to distribute sensitive records, or whether an access-controlled document service with auditable permissions would be safer and easier to administer.
The three-entry example shows the core of a dictionary test on a PDF that you created: obtain authorization, create or retain a controlled original, test specific candidate passwords, interpret a positive or negative result, and protect any recovered content. Its success is predetermined by the laboratory setup. It does not demonstrate a vulnerability in AES, justify testing somebody else’s document, or promise recovery of an unknown real-world password.
Good security writing distinguishes a working educational example from a universal method. A small, reproducible laboratory case provides that distinction. When the document is real and the password is truly lost, first investigate lawful replacement, backups and existing credential custody; treat dictionary testing as a limited option with a clearly defined stopping point, not an entitlement to someone else’s information.