利用python暴力破解压缩文件密码
程序员文章站
2022-05-11 14:12:01
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()
上一篇: 从没有设计到最极致设计 历代小米手机盘点:进步巨大
下一篇: 51nod 1241 特殊的排序