-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
45 lines (34 loc) · 1.02 KB
/
solution.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
import os, hashlib, time
from itertools import permutations
startTime=time.time()
answer= "you are doing great but take care of the order"
toMatch= hashlib.md5(answer.encode()).hexdigest()
toCheck="here's one key :"
found=[]
for i in range(200):
os.chdir('./randomBox'+str(i))
for j in range(200):
with open('flag'+str(j)+'.c', 'r') as file:
data= file.readlines()
for line in data:
lineAsList= line.split()
if ':' in lineAsList:
found.append(lineAsList[-1])
os.chdir('..')
print(found)
matched= False
count =0
for perm in permutations(found):
permStr= ' '.join(perm)
permHash= hashlib.md5(permStr.encode()).hexdigest()
if toMatch==permHash or permStr=="":
print('matched answer: '+permStr)
matched= True
break
else:
count+=1
# print(count,'perms checked')
if not matched:
print('nothing matched, check the code ')
endTime=time.time()
print(endTime-startTime,'seconds elapsed')