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()
利用多线程版
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”
|