pdf检察暗码

[复制链接]
发表于 前天 07:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
pdf有两种暗码方式,一种是打开后进入文件内容页面后必要暗码才华举行修改等操纵,网上有很多方式举行移除暗码操纵,第二种是打开就必要暗码,我这里简单纪录一个暴力破解的方式,仅供参考
  1. import PyPDF2
  2. import itertools
  3. import string
  4. def decrypt_pdf(input_file, output_file, password):
  5.     with open(input_file, "rb") as file:
  6.         reader = PyPDF2.PdfReader(file)
  7.         if reader.is_encrypted:
  8.             try:
  9.                 if reader.decrypt(password):
  10.                     writer = PyPDF2.PdfWriter()
  11.                     for page in reader.pages:
  12.                         writer.add_page(page)
  13.                     with open(output_file, "wb") as output_pdf_file:
  14.                         writer.write(output_pdf_file)
  15.                         print(f"解密后文件已保存为: {output_file}")
  16.                         return True
  17.                 else:
  18.                     print(f"密码'{password}'错误")
  19.             except Exception as e:
  20.                 print(f"解密失败: {e}")
  21.         else:
  22.             print("该 PDF 文件没有加密。")
  23.         return False
  24. def generate_passwords(length):
  25.     characters = string.ascii_letters + string.digits  # 字母加数字方式 可以添加其他字符
  26.     for password in itertools.product(characters, repeat=length):
  27.         yield ''.join(password)
  28. if __name__ == "__main__":
  29.     input_pdf_path = r"d:"  # 输入你的加密 PDF 文件路径
  30.     output_pdf_path = r"d:"  # 输出解密后文件的路径
  31.     # 尝试生成长度为1到4的所有可能的密码
  32.     for length in range(1, 5):  # 可调整最大长度
  33.         print(f"尝试长度为 {length} 的密码...")
  34.         for password in generate_passwords(length):
  35.             if decrypt_pdf(input_pdf_path, output_pdf_path, password):
  36.                 break
复制代码

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表