Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2910626

Browse files
committed
修复报错的bug 还是存在中文乱码
1 parent bf8cba9 commit 2910626

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

暴力破解zip/1.zip

970 Bytes
Binary file not shown.

暴力破解zip/main.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
start = time.time()
1212

1313
# chr(97) -> 'a' 这个变量保存了密码包含的字符集
14-
# dictionaries = [chr(i) for i in
15-
# chain(range(97, 123), # a - z
16-
# range(65, 91), # A - Z
17-
# range(48, 58))] # 0 - 9
18-
#
14+
dictionaries = [chr(i) for i in
15+
chain(range(97, 123), # a - z
16+
range(65, 91), # A - Z
17+
range(48, 58))] # 0 - 9
18+
1919
# dictionaries.extend(['.com', 'www.']) # 添加自定义的字符集
20-
dictionaries = [chr(i) for i in range(48, 58)]
20+
# dictionaries=[chr(i) for i in range(48,58)]
2121

22-
file_name = r"C:\Users\lenovo\PycharmProjects\leetcode-python-\暴力破解zip\AI算法工程师手册.zip" # 你的文件路径
2322

2423

2524
def all_passwd(dictionaries: List[str], maxlen: int):
@@ -37,26 +36,29 @@ def helper(temp: list, start: int, n: int):
3736
yield from helper([0] * maxlen, 0, maxlen)
3837

3938

40-
zfile = ZipFile(file_name, 'r') # 很像open
41-
4239

4340
def extract(zfile: ZipFile, pwd: str) -> bool:
4441
# zfile: 一个ZipFile类, pwd: 密码
4542
try:
46-
print(pwd)
47-
zfile.extractall(path='.', pwd=pwd.encode('utf-8')) # 密码输入错误的时候会报错
48-
now = time.time() # 故使用 try - except 语句
43+
zfile.extractall(path='.', pwd=pwd.encode(
44+
'utf-8')) # 密码输入错误的时候会报错 # 故使用 try - except 语句
4945
print("Password is: {}".format(pwd)) # 将正确的密码输出到控制台
5046
return True
5147
except:
5248
return False
53-
54-
5549
# 用 bool 类型的返回值告诉主程序是否破解成功 (意思就是返回 True 了以后就停止)
5650

57-
lengths = [3] # 密码长度
51+
lengths = [8] # 密码长度
5852
total = sum(len(dictionaries) ** k for k in lengths) # 密码总数
5953

60-
for pwd in tqdm(chain.from_iterable(all_passwd(dictionaries, maxlen) for maxlen in lengths), total=total):
61-
if extract(zfile, pwd): # 记得extract函数返回的是bool类型的哦
62-
break
54+
55+
def main():
56+
for pwd in tqdm(chain.from_iterable(all_passwd(dictionaries, maxlen) for maxlen in lengths), total=total):
57+
if extract(zfile, pwd): # 记得extract函数返回的是bool类型的哦
58+
break
59+
60+
61+
if __name__ == '__main__':
62+
file_name = r"C:\Users\lenovo\PycharmProjects\leetcode-python-\暴力破解zip\1.zip" # 你的文件路径
63+
zfile = ZipFile(file_name, 'r') # 很像open
64+
main()

0 commit comments

Comments
 (0)