11
11
start = time .time ()
12
12
13
13
# 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
+
19
19
# dictionaries.extend(['.com', 'www.']) # 添加自定义的字符集
20
- dictionaries = [chr (i ) for i in range (48 , 58 )]
20
+ # dictionaries= [chr(i) for i in range(48,58)]
21
21
22
- file_name = r"C:\Users\lenovo\PycharmProjects\leetcode-python-\暴力破解zip\AI算法工程师手册.zip" # 你的文件路径
23
22
24
23
25
24
def all_passwd (dictionaries : List [str ], maxlen : int ):
@@ -37,26 +36,29 @@ def helper(temp: list, start: int, n: int):
37
36
yield from helper ([0 ] * maxlen , 0 , maxlen )
38
37
39
38
40
- zfile = ZipFile (file_name , 'r' ) # 很像open
41
-
42
39
43
40
def extract (zfile : ZipFile , pwd : str ) -> bool :
44
41
# zfile: 一个ZipFile类, pwd: 密码
45
42
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 语句
49
45
print ("Password is: {}" .format (pwd )) # 将正确的密码输出到控制台
50
46
return True
51
47
except :
52
48
return False
53
-
54
-
55
49
# 用 bool 类型的返回值告诉主程序是否破解成功 (意思就是返回 True 了以后就停止)
56
50
57
- lengths = [3 ] # 密码长度
51
+ lengths = [8 ] # 密码长度
58
52
total = sum (len (dictionaries ) ** k for k in lengths ) # 密码总数
59
53
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