共计 599 个字符,预计需要花费 2 分钟才能阅读完成。
import os
import time
from zipfile import ZipFile
import itertools as its
def create_pwd(words, len):
for i in range(1, len + 1):
base = its.product(words, repeat=i)
for b in base:
yield "".join(b)
def crack_zip(path, pwd):
type_ = os.path.splitext(path)[-1][1:]
if type_ == "zip":
with ZipFile(path, "r") as zip:
try:
zip.extractall("./unzip", pwd=str(pwd).encode("utf-8"))
end_time = time.time()
print(f" 解压密码:{pwd}")
print(f" 花费时间:{round(end_time-start_time, 2)} 秒 ")
return True
except Exception as e:
print(pwd, e)
if __name__ == "__main__":
start_time = time.time()
words = "1234567890abc"
length = 6
for p in create_pwd(words, length):
flag = crack_zip("./pdl1.zip", p)
if flag:
break
正文完