利用python暴力破解压缩文件密码


import randomimport sysimport zipfileimport timefrom threading import Threadfrom multiprocessing import Process

class MyIterator:    # letters = '0123456789abcdefghijklmnopqrstuvwxyz'    letters = '1234zjcv'    min_dig = 0    max_dig = 0

    def __init__(self, min_dig, max_dig):

        if min_dig < max_dig:            self.min_dig = min_dig            self.max_dig = max_dig

        else:            self.min_dig = max_dig            self.max_dig = min_dig

    def __iter__(self):        return self

    def __next__(self):        rst = str()        for item in range(0,random.randrange(self.min_dig,self.max_dig+1)):            rst += random.choice(MyIterator.letters)        return rst

def extract():    start_time = time.time()    zfile = zipfile.ZipFile('123.zip')

    for p in MyIterator(4, 6):        print(p)        try:            zfile.extractall(path='.', pwd=str(p).encode('utf-8'))            print('文件密码为:{}'.format(p))

            now_time = time.time()            print('破解用时:{}'.format(now_time - start_time))            sys.exit()

        except Exception as e:            pass

if __name__ == '__main__':    tl = Thread(target=extract)    tl.start()    tl.join()
上一篇:在DWZ框架中整合kindeditor复文本框控件


下一篇:Anagrams leetcode java