#! python3
# 暴力PDF口令破解程序.py
import PyPDF2
import threading
import pyperclip # 复制到粘贴栏,方便查询密码
active = False # 表示未找到密码
# 大写形式
pdfObj = open("encrypted.pdf", "rb")
readerObj = PyPDF2.PdfFileReader(pdfObj)
textObj = open("dictionary.txt", "rt")
for line in textObj.readlines():
if readerObj.decrypt(line[0:-1]): # 末尾有换行符,应去除
print("解密成功!密码:",line[0:-1])
active = True
pyperclip.copy(line[0:-1])
exit(0)
else:
print("解密失败!密码:",line[0:-1])
# 小写形式
if active == False:
for line in textObj.readlines():
if readerObj.decrypt(line.lower()[0:-1]):
print("解密成功!密码:",line.lower()[0:-1])
pyperclip.copy(line.lower()[0:-1])
exit(0)
else:
print("解密失败!密码:",line.lower()[0:-1])
pdfObj.close()
textObj.close()
利用多线程版
#! python3
# 暴力PDF口令破解程序.py
import PyPDF2
import threading
import pyperclip
def upperDecode():
# 大写形式
pdfObj = open("encrypted.pdf", "rb")
readerObj = PyPDF2.PdfFileReader(pdfObj)
textObj = open("dictionary.txt", "rt")
for line in textObj.readlines():
if readerObj.decrypt(line[0:-1]):
print("解密成功!密码:",line[0:-1])
pyperclip.copy(line[0:-1])
exit(0)
else:
print("解密失败!密码:",line[0:-1])
def lowerDecode():
# 小写形式
pdfObj = open("encrypted.pdf", "rb")
readerObj = PyPDF2.PdfFileReader(pdfObj)
textObj = open("dictionary.txt", "rt")
for line in textObj.readlines():
if readerObj.decrypt(line.lower()[0:-1]):
print("解密成功!密码:",line.lower()[0:-1])
pyperclip.copy(line.lower()[0:-1])
exit(0)
else:
print("解密失败!密码:",line.lower()[0:-1])
pdfObj.close()
textObj.close()
threadObj1 = threading.Thread(target=upperDecode)
threadObj2 = threading.Thread(target=lowerDecode)
threadList = [threadObj1,threadObj2]
threadObj1.start()
threadObj2.start()
for threadObj in threadList:
threadObj.join()
注:最终密码是小写的“rosebud”