用Python怎样破解zip加密文件,操作是什么
Admin 2022-08-26 群英技术资讯 1256 次浏览
今天这篇给大家分享的知识是“用Python怎样破解zip加密文件,操作是什么”,小编觉得挺不错的,对大家学习或是工作可能会有所帮助,对此分享发大家做个参考,希望这篇“用Python怎样破解zip加密文件,操作是什么”文章能帮助大家解决问题。解压时可以提供密码zfile.extractall("./", pwd=password.encode("utf8"))
通过函数itertools.permutations("abc", 3)实现全字符的全排列:abc/acb/bca/bac/cab/cba
本文介绍的zip文件知道密码一共是4位的,密码字符的范围是a-z1-0。并且不存在重复字符的,不会有“aabb”的密码。zip压缩时是选择了zip传统加密!
导入zipfile模块,使用其中的extractall()函数。
import itertools
filename = "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 zipfile
import itertools
filename = "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 zipfile
import itertools
filename = "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 False
chars = "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
此方法可以是实现破解zip文件的密码,python可以完成一些好玩的事情。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章给大家分享的是有关python算法的内容,主要介绍python实现二分查找和选择排序。小编觉得挺实用的,因此分享给大家做个参考,感兴趣的朋友一起跟随小编看看吧。
这篇文章主要为大家介绍了python NetworkX库生成并绘制带权无向图的实现示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
这篇文章主要介绍了七个Python必备的GUI库,帮助大家更好的理解和学习使用python制作gui程序,感兴趣的朋友可以了解下
本篇文章给大家带来了关于Python的相关知识,Python 在 3.7 的时候引入了一个模块:contextvars,从名字上很容易看出它指的是上下文变量,下面就来和大家详细讲讲如何使用contextvars实现管理上下文变量,希望对大家有帮助。
这篇文章介绍了使用python读取文件夹中图片的图片名并写入excel表格的方法。对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008