-
Notifications
You must be signed in to change notification settings - Fork 0
/
base1782.py
52 lines (43 loc) · 1.08 KB
/
base1782.py
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
48
49
50
51
52
#!/usr/bin/env python
# encoding: utf-8
import base64
import hashlib
import itertools
def check(src):
m1 = hashlib.md5()
m1.update(src)
if m1.hexdigest() == '16478a151bdd41335dcd69b270f6b985':
return True
else:
return False
def generate(word):
n = len(word)
tuple = [()]
result = []
for i in range(n):
tuple.extend(list(itertools.combinations(range(n),i+1)))
for i in tuple:
result.append(change(word,i))
return result
def change(word,tuple):
b = list(word)
result = []
for i in range(len(b)):
if b[i].isalpha():
if i in tuple:
result.append(word[i].lower())
else:
result.append(word[i])
else:
result.append(word[i])
return ''.join(result)
def decrypt(word):
for i in generate(word):
if check(base64.b64decode(i)):
return i
else:
print 'not '+ i
if __name__ == '__main__':
word = 'YMFZZTY0D3RMD3RMMTIZ'
result = decrypt(word)
print 'flag is '+ base64.b64decode(result)