python3入门与进阶.zip密码_详解python破解zip文件密码的方法

1、单线程破解纯数字密码

注意: 不包括数字0开头的密码

import zipfile,time,sys

start_time = time.time()

def extract():

zfile = zipfile.ZipFile('IdonKnow.zip')#读取压缩包,如果用必要可以加上'r'

for num in range(1,99999,1):

try:

pwd = str(num)

zfile.extractall(path='.',pwd=pwd.encode('utf-8'))

print ("当前压缩密码为:",pwd)

end_time = time.time()

print ('单线程破解压缩包花了%s秒'%(end_time-start_time))

sys.exit(0)

except Exception as e:

pass

if __name__=="__main__":

extract()

破解结果:

2020011309500215.png

2、多线程破解纯数字密码

注意: 不包括数字0开头的密码

import zipfile,time,threading

start_time = time.time()

flag = True # 用于判断线程是否需要终止,为True时程序执行

def extract(password, file):

try:

password = str(password)

file.extractall(path='.', pwd=password.encode('utf-8'))

print ("当前压缩密码为:",password)

end_time = time.time()

print ('多线程破解压缩包花了%s秒'%(end_time-start_time))

global flag

flag = False#成功解压其余线程终止

except Exception as e:

pass

def main():

zfile = zipfile.ZipFile("test.zip", 'r')

for number in range(1, 99999,1):

if flag:

thr1 = threading.Thread(target=extract, args=(number, zfile))

thr2 = threading.Thread(target=extract, args=(number, zfile))

thr1.start()

thr2.start()

thr1.join()

thr2.join()

if __name__ == '__main__':

main()

破解结果:

2020011309500216.png

提示: 多线程对数字型的运算没有多大帮助

3、破解英文+数字型的密码

import random,zipfile,time,sys

class MyIter():

cset = 'abcdefghijklmnopqrstuvwxyz0123456789'

def __init__(self,min,max):#迭代器实现初始方法,传入参数

if min < max:

self.minlen = min

self.maxlen = max

else:

self.ninlen = max

self.maxlen = min

def __iter__(self):#直接返回slef实列对象

return self

def __next__(self):#通过不断地轮循,生成密码

rec = ''

for i in range(0,random.randrange(self.minlen,self.maxlen+1)):

rec += random.choice(MyIter.cset)

return rec

def extract():

start_time = time.time()

zfile = zipfile.ZipFile('test1.zip','r')

for password in MyIter(1,4):#随机迭代出1~4位数的密码,在不明确位数的时候做相应的调整

if zfile:

try:

zfile.extractall(path='.',pwd=str(password).encode('utf-8'))

print ("当前压缩密码为:",password)

end_time = time.time()

print ('当前破解压缩包花了%s秒'%(end_time-start_time))

sys.exit(0)

except Exception as e:

print ('pass密码:',password)

pass

if __name__=="__main__":

extract()

破解结果:

2020011309500317.png

总结

以上所述是小编给大家介绍的python破解zip文件密码的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python中,`zip()`函数是用来将多个可迭代对象(如列表、元组、字典、集合等)打包成一个元组的列表的方法。在Python 2和Python 3中有一些不同之处。在Python 3中,`zip()`函数返回的是一个对象,为了展示列表,需要手动使用`list()`行转换。 下面是一个示例代码: ```python a = [1, 2, 3] b = [4, 5, 6] c = [4, 5, 6, 7, 8] zipped = zip(a, b) # 打包为元组的列表 [(1, 4), (2, 5), (3, 6)] zip(a, c) # 元素个数与最短的列表一致 [(1, 4), (2, 5), (3, 6)] zip(*zipped) # 与 zip 相反,*zipped 可理解为解压,返回二维矩阵式 [(1, 2, 3), (4, 5, 6)] list(zip(*zipped)[1]) # 与 zip 相反,*zipped 可理解为解压,严格讲还是元组列表, [4, 5, 6 # 不过元组可以转为列表 ``` 以上代码演示了`zip()`函数的用法,通过对多个列表行打包、解压等操作。 希望这个解释能够帮助你理解`python.zip()`是如何使用的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python学习系列之zip函数](https://blog.csdn.net/answer3lin/article/details/86505410)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python zip函数 详解(全)](https://blog.csdn.net/weixin_47872288/article/details/128735490)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值