利用python暴力破解压缩文件密码
程序员文章站
2022-10-16 15:29:18
import randomimport sysimport zipfileimport timefrom threading import Threadfrom multiprocessing import Processclass MyIterator: # letters = '01234567... ......
import random
import sys
import zipfile
import time
from threading import thread
from 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()