
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Crack PDF Files in Python?
Python has a rich collection of libraries that are used for multiple purposes like creating and developing applications, web development, scientific computation, software testing, machine learning, and many more. Python is also used for testing and developing system applications in terms of information security. There are several other libraries and tools available that contain specific scripts used for creating hashes, information gathering, information retrieval, encryption and decryption, web crawling, spoofing, and many more.
In this article, we will create a program that will decrypt a password protected PDF document. For decryption, we will use a word list that contains some common passwords and it will help to decrypt the pdf document.
In order to create a pdf cracker, we will import the pikepdf library. Once downloaded, we can include it in our notebook. For reference, we will use this wordlist as an example that contains 5000 common passwords in it.
Example
import pikepdf from tqdm import tqdm #Loading password list password = [line.strip() for line in open("wordlist.txt")] #iterate over all the passwords for paswrd in tqdm(password, "Cracking PDF"): try: #open PDF file with pikepdf.open("protected.pdf", password=paswrd) as pdf: #If password matches then break the loop and print the output print("Password found:", paswrd) break except pikepdf._qpdf.PasswordError as e: #If password not found then continue continue
Output
Running the above code will first find the password and then print it as the output.
- Related Articles
- How to convert PDF files to Excel files using Python?
- Working with PDF files in Python?
- How to download all pdf files with selenium python?
- How to Merge PDF Files in Bash?
- How to search contents of multiple pdf files on Linux?
- How to Convert Multiple Workbooks or Worksheets to PDF Files at Once in Excel?
- How to add PDF in Tkinter GUI Python?
- How to convert HTML to PDF using Python
- How to compare files in Python
- How to Crack UPSC CSE Prelims
- How to convert CSV File to PDF File using Python?
- Convert PDF to CSV using Python
- Extract hyperlinks from PDF in Python
- How to import other Python files?
- How to safely open/close files in Python?
