前女友發(fā)來加密的"520快樂.pdf",我用python破解開之后,卻發(fā)現
事情是這樣的
520晚上,正跟隊友 啪啪啪 組團開黑
突然,微信上前女友的頭像跳動了起來
快一年了,難道是想要復合?
發(fā)來的竟是一個 " 520快樂.pdf " 的加密文件
想復合就直說嘛
干嘛還要搞的這么有情趣,讓我破解
伴隨著我隊友刺耳的罵街聲
我平靜而果斷的的退出了游戲
擼出了,我的python代碼。。。
明確需求
1、根據對前女友的了解,密碼為4位純數字。(代碼中可以自定義代碼生成函數,生成各種組合的密碼,進行破解)
2、520快樂.pdf 如下 ↓ ↓ ↓ 加密了打不開
安裝pdf工具模塊
pip install PyPDF2
PS D:\> pip install PyPDF2 Looking in indexes: http://mirrors.aliyun.com/pypi/simple Collecting PyPDF2 Downloading http://mirrors.aliyun.com/pypi/packages/b4/01/68fcc0d43daf4c6bdbc6b33cc3f77bda531c86b174cac56ef0ffdb96faab/PyPDF2-1.26.0.tar.gz (77 kB) |████████████████████████████████| 77 kB 919 kB/s Using legacy 'setup.py install' for PyPDF2, since package 'wheel' is not installed. Installing collected packages: PyPDF2 Running setup.py install for PyPDF2 ... done Successfully installed PyPDF2-1.26.0 PS D:\>
如何給pdf加密碼?
要想破解加密的pdf文件,就要知道如何給pdf加密??梢酝ㄟ^PyPDF2模塊,給pdf加密。
代碼如下:
import PyPDF2 #加密PDF def encrypt(old_Path, new_Path): """ :param old_Path: 待加密文件的路徑名 :param new_Path: 加密之后的文件路徑名 """ with open(old_Path, 'rb') as pdfFile: pdfReader = PyPDF2.PdfFileReader(pdfFile) # 創(chuàng)建pdfWriter對象用于寫出PDF文件 pdfWriter = PyPDF2.PdfFileWriter() # pdf對象加入到pdfWriter對象中 for pageNum in range(pdfReader.numPages): pdfWriter.addPage(pdfReader.getPage(pageNum)) # 密碼設置為8888 pdfWriter.encrypt('8888') with open(new_Path, 'wb') as resultPDF: pdfWriter.write(resultPDF) print('加密成功!')
如何破解加密pdf文件
1、生成四位數純數字密碼的方法
你可以根據需求,自己定義密碼的位數,這里只定義4位純數字密碼
#你可以根據需求,自己定義密碼的位數,這里只定義4位純數字密碼 for i in range(10000): #生成四位數密碼 pwd=str(i).zfill(4) print(pwd)
2、破解pdf函數代碼
引用pypdf2模塊,調用pdfReader.decrypt('密碼'),通過不停的遍歷我們生成的密碼。
破解密碼函數 如下:
def decrypt(old_Path, new_Path): """ :param old_Path: 待加密文件的路徑名 :param new_Path: 加密之后的文件路徑名 """ with open(old_Path, 'rb') as pdfFile: pdfReader = PyPDF2.PdfFileReader(pdfFile) pdfWriter = PyPDF2.PdfFileWriter() # 判斷文件是否加密 if pdfReader.isEncrypted: # 判斷密碼是否正確 for i in range(10000): #生成四位數密碼 pwd=str(i).zfill(4) if pdfReader.decrypt(pwd): for pageNum in range(pdfReader.numPages): pdfWriter.addPage(pdfReader.getPage(pageNum)) with open(new_Path, 'wb') as resultFile: pdfWriter.write(resultFile) print('成功了!密碼是:'+pwd) else: print('密碼錯了!哼~~~') else: print('沒有加密呀~~~')
開始破解
代碼已經準備好,下面,我們正式開始破解~~~
效果如下 ↓ ↓ ↓
幾秒之后,密碼破解成功。
emmm ,密碼居然是 1314
完整代碼
https://download.csdn.net/download/weixin_42350212/19777145
故事結尾
密碼居然是1314
讓我有點不知所措呢
迫不及待的打開 “520快樂.pdf”
啪啪啪
歡快的輸入破解出的密碼 1314
----The End----
到此這篇關于前女友發(fā)來加密的"520快樂.pdf",我用python破解開之后,卻發(fā)現...的文章就介紹到這了,更多相關python破解加密內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python3中內置類型bytes和str用法及byte和string之間各種編碼轉換 問題
這篇文章主要介紹了Python3中內置類型bytes和str用法及byte和string之間各種編碼轉換問題,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09