从零开始学习python-暴力破译zip文件 7月11日

Python

                                                                                                                     ---小白121的记录笔记


暴力破译ZIP压缩包文件

需要调用的库

  • itertools
  • zipfile
  • time                                                                                
import zipfile
import time
from itertools import product

path = input('please input decipher the ZIP File: ')

def pwd(x=6):
    iter = ['1234567890']
    for i in iter:
        for repeat in range(1, x+1):
            for ps in product(i, repeat = repeat):
                yield''.join(ps)

def run(path, passwd):
    if path[-4:] == '.zip':
        zip = zipfile.ZipFile(path, 'r', zipfile.zlib.DEFLATED)
        try:
            zip.extractall(path='C:\\Users\\121812\\Desktop\\', members=zip.namelist(), pwd=passwd.encode('utf-8'))
            print("\n\tsuccess! passwd is %s\t\n"%passwd)
            zip.close()
            return True
        except:
            print('--- error! passwd : %s ---' %passwd)
            return False


if __name__ == '__main__':
    start = time.clock()
    print("--- decipher now ! ---")
    for temp in pwd(8):
        if run(path, temp):
            break
    print('End speed time is %s' %(time.clock() - start))

    

                                                                                                                改编自---童年的夏天

单词:

decipher    破译

member    成员

compress    压缩

yield    屈服

got    得到

猜你喜欢

转载自blog.csdn.net/qq_42184699/article/details/81007498