PDF passwordCracker

import PyPDF2 from itertools import product import string import time def crack_pdf_bruteforce(pdf_path, max_length=4, charset=string.ascii_letters + string.digits): start_time = time.time() with open(pdf_path, 'rb') as f: pdf_reader = PyPDF2.PdfReader(f) if not pdf_reader.is_encrypted: print("šŸ“„ PDF is not password protected.") return total_attempts = 0 for length in range(1, max_length + 1): print(f"\nšŸ” Trying passwords of length {length}...") for pwd_tuple in product(charset, repeat=length): password = ''.join(pwd_tuple) print(f"šŸ” Trying password: {password}", end='\r') # Overwrites the line for cleaner output total_attempts += 1 try: if pdf_reader.decrypt(password) == 1: print(f"\nāœ… Password found: {password}") print(f"šŸ”¢ Total attempts: {total_attempts}") print(f"ā±ļø Time taken: {time.time() - start_time:.2f} seconds") return except Exception: pass print("\nāŒ Password not found.") print(f"šŸ”¢ Total attempts: {total_attempts}") print(f"ā±ļø Time taken: {time.time() - start_time:.2f} seconds") if __name__ == "__main__": pdf_file = input("Enter path to encrypted PDF: ").strip().strip('"').strip("'") crack_pdf_bruteforce(pdf_file, max_length=4)

Code output

šŸ” Trying passwords of length 1... šŸ” Trying password: 9 šŸ” Trying passwords of length 2... šŸ” Trying password: 99 šŸ” Trying passwords of length 3...