使用python怎么破解zip文件密码

发布时间:2021-05-21 17:55:22 作者:Leah
来源:亿速云 阅读:143

这期内容当中小编将会给大家带来有关使用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()

破解结果:

使用python怎么破解zip文件密码

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()

破解结果:

使用python怎么破解zip文件密码

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

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()

破解结果:

使用python怎么破解zip文件密码

python主要应用领域有哪些

1、云计算,典型应用OpenStack。2、WEB前端开发,众多大型网站均为Python开发。3.人工智能应用,基于大数据分析和深度学习而发展出来的人工智能本质上已经无法离开python。4、系统运维工程项目,自动化运维的标配就是python+Django/flask。5、金融理财分析,量化交易,金融分析。6、大数据分析。

上述就是小编为大家分享的使用python怎么破解zip文件密码了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 使用Python破解ZIP或RAR压缩文件密码的方法
  2. python破解zip加密文件的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python

上一篇:使用Django怎么批量插入数据

下一篇:怎么在Linux环境中部署ActiveMQ

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》