-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path解压密码.py
More file actions
47 lines (39 loc) · 1.24 KB
/
Copy path解压密码.py
File metadata and controls
47 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import zipfile
import random
import time
import sys
class MyIterator():
# 单位字符集合
letters = 'abcdefghijklmnopqrstuvwxyz012345678'
min_digits = 0
max_digits = 0
def __init__(self, min_digits, max_digits):
# 实例化对象时给出密码位数范围,一般4到10位
if min_digits < max_digits:
self.min_digits = min_digits
self.max_digits = max_digits
else:
self.min_digits = max_digits
self.max_digits = min_digits
# 迭代器访问定义
def __iter__(self):
return self
def __next__(self):
rst = str()
for item in range(0, random.randrange(self.min_digits, self.max_digits+1)):
rst += random.choice(MyIterator.letters)
return rst
def extract():
start_time = time.time()
zfile = zipfile.ZipFile("test.zip")
for p in MyIterator(5, 6):
try:
zfile.extractall(path=".", pwd=str(p).encode('utf-8'))
print("the password is {}".format(p))
now_time = time.time()
print("spend time is {}".format(now_time-start_time))
sys.exit(0)
except Exception as e:
pass
if __name__ == '__main__':
extract()