前女友發(fā)來加密的"520快樂.pdf",我用python破解開之后,卻發(fā)現(xiàn)
事情是這樣的
520晚上,正跟隊友 啪啪啪 組團開黑
突然,微信上前女友的頭像跳動了起來
快一年了,難道是想要復(fù)合?
發(fā)來的竟是一個 " 520快樂.pdf " 的加密文件
想復(fù)合就直說嘛
干嘛還要搞的這么有情趣,讓我破解
伴隨著我隊友刺耳的罵街聲
我平靜而果斷的的退出了游戲
擼出了,我的python代碼。。。
明確需求
1、根據(jù)對前女友的了解,密碼為4位純數(shù)字。(代碼中可以自定義代碼生成函數(shù),生成各種組合的密碼,進行破解)
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)) # 密碼設(shè)置為8888 pdfWriter.encrypt('8888') with open(new_Path, 'wb') as resultPDF: pdfWriter.write(resultPDF) print('加密成功!')
如何破解加密pdf文件
1、生成四位數(shù)純數(shù)字密碼的方法
你可以根據(jù)需求,自己定義密碼的位數(shù),這里只定義4位純數(shù)字密碼
#你可以根據(jù)需求,自己定義密碼的位數(shù),這里只定義4位純數(shù)字密碼 for i in range(10000): #生成四位數(shù)密碼 pwd=str(i).zfill(4) print(pwd)
2、破解pdf函數(shù)代碼
引用pypdf2模塊,調(diào)用pdfReader.decrypt('密碼'),通過不停的遍歷我們生成的密碼。
破解密碼函數(shù) 如下:
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): #生成四位數(shù)密碼 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('沒有加密呀~~~')
開始破解
代碼已經(jīng)準備好,下面,我們正式開始破解~~~
效果如下 ↓ ↓ ↓
幾秒之后,密碼破解成功。
emmm ,密碼居然是 1314
完整代碼
https://download.csdn.net/download/weixin_42350212/19777145
故事結(jié)尾
密碼居然是1314
讓我有點不知所措呢
迫不及待的打開 “520快樂.pdf”
啪啪啪
歡快的輸入破解出的密碼 1314
----The End----
到此這篇關(guān)于前女友發(fā)來加密的"520快樂.pdf",我用python破解開之后,卻發(fā)現(xiàn)...的文章就介紹到這了,更多相關(guān)python破解加密內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。