python编程快速上手办公自动化_关于暴力破解pdf口令程序的解答

#! 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”

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Python编程快速上手可以帮助我们实现繁琐工作的自动化。Python是一种简单易学的编程语言,能够简化我们的工作流程,提高工作效率。 首先,Python具有丰富的函数库和开源工具,使得编写自动化脚本变得更加容易。我们可以使用Python来编写脚本,通过调用不同的库函数来完成各种任务,例如文件操作、数据处理、网络请求等。这些库函数已经被开发者广泛使用和测试,可以为我们节省大量的时间和精力。 其次,Python编程语言具有简洁的语法和优雅的代码风格。相比其他的编程语言,Python的代码更易读、易理解,这使得我们可以更快地上手并编写出高效的自动化脚本。Python的语法结构简单明了,可以大大缩减代码量,提高编码效率。 此外,Python还有丰富的第三方库和工具,如TensorFlow、Pandas、Numpy等,可以方便地进行数据分析、人工智能、机器学习等领域的工作。这些工具以及其提供的函数和方法大大简化了复杂任务的处理,帮助我们快速解决实际问题。 总的来说,Python编程快速上手能够让我们更方便地进行繁琐工作的自动化。它的简单易学、优雅的代码风格以及丰富的函数库和工具使得我们能够高效地编写自动化脚本,提高工作效率,减少重复劳动,为我们节约时间和精力。无论是处理数据、完成文件操作,还是进行网络请求,Python都可以成为我们的得力助手。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值