Python 官方文档:入门教程 => 点击学习
本篇内容主要讲解“怎么利用python破解zip加密文件”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么利用Python破解zip加密文件”吧!一、破解zip加密文件的思路准备一个加密的zip
本篇内容主要讲解“怎么利用python破解zip加密文件”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么利用Python破解zip加密文件”吧!
准备一个加密的zip文件。
zipfile模块可以解压zip文件。
解压时可以提供密码zfile.extractall("./", pwd=passWord.encode("utf8"))
itertools.permutations实现全字符的全排列。
通过函数itertools.permutations("abc", 3)实现全字符的全排列:abc/acb/bca/bac/cab/cba
本文介绍的zip文件知道密码一共是4位的,密码字符的范围是a-z1-0。并且不存在重复字符的,不会有“aabb”的密码。zip压缩时是选择了zip传统加密!
导入zipfile模块,使用其中的extractall()函数。
import itertoolsfilename = "readme.zip"# 创建一个解压的函数,入参为文件名和密码# 并使用try-except,避免报错中断程序。def uncompress(file_name, pass_word): try: with zipfile.ZipFile(file_name) as z_file: z_file.extractall("./", pwd=pass_word.encode("utf-8")) return True except: return False
import zipfileimport itertoolsfilename = "readme.zip"# 创建一个解压的函数,入参为文件名和密码# 并使用try-except,避免报错中断程序。def uncompress(file_name, pass_word): try: with zipfile.ZipFile(file_name) as z_file: z_file.extractall("./", pwd=pass_word.encode("utf-8")) return True except: return False# chars是密码可能的字符集chars = "abcdefghijklmnopqrstuvwxyz0123456789"for c in itertools.permutations(chars, 4): password = ''.join(c) print(password) result = uncompress(filename, password) if not result: print('解压失败。', password) else: print('解压成功。', password) break
文件压缩时,一些注意的事项:
查过一些资料,zip压缩文件密码最长为12位,在原来的程序上增加上一个for循环就可以实现破解密码了。
import zipfileimport itertoolsfilename = "readme.zip"def uncompress(file_name, pass_word): try: with zipfile.ZipFile(file_name) as z_file: z_file.extractall("./", pwd=pass_word.encode("utf-8")) return True except: return Falsechars = "abcdefghijklmnopqrstuvwxyz0123456789"for i in range(12): for c in itertools.permutations(chars, i): password = ''.join(c) print(password) result = uncompress(filename, password) if not result: print('解压失败。', password) else: print('解压成功。', password) break
到此,相信大家对“怎么利用python破解zip加密文件”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
--结束END--
本文标题: 怎么利用python破解zip加密文件
本文链接: https://www.lsjlt.com/news/329924.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0