Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav1812 committed Apr 23, 2020
1 parent 810b632 commit 5096bf0
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
47 changes: 47 additions & 0 deletions projectFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import shutil, os

for i in range(200):
path= './randomBox'+str(i)
os.mkdir(path)
os.chdir('./'+path)
for j in range(200):
fileName='flag'+str(j)+'.c'
file= open(fileName,'w')
file.write('#include<stdio.h> \n int main(){ \nprintf("this is flag: '+str(j)+' "); \n} ' )
file.close()
os.chdir('..')
print(os.path.abspath(path))


































19 changes: 19 additions & 0 deletions projectFile2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os, random

keys=['this', 'was', 'the', 'correct', 'key', 'but', 'the', 'correct', 'order', 'can', 'be', 'different',
'so', 'better', 'try', 'a', 'bruteforce']

selected_folders=[]
for i in range(len(keys)):
selected_folders.append(random.randrange(0,200,1))

for i in range(len(selected_folders)):
os.chdir('./randomBox'+str(selected_folders[i]))
selected_file= random.randrange(0,200,1)
fileName='flag'+str(selected_file)+'.c'
file=open(fileName,'a')
file.write('//here\'s one key : '+keys[i])
file.close()
print('inserted a key in box number:'+str(selected_folders[i])+'\'s file number: '+str(selected_file))
os.chdir('..')
print('done')
43 changes: 43 additions & 0 deletions solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os, hashlib, time
from itertools import permutations

startTime=time.time()
toMatch='611d6663e938213f9643144650180a8d'

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(len(found))
matched= False
count =0
for perm in permutations(found):
permStr= ' '.join(perm)
permHash= hashlib.md5(permStr.encode()).hexdigest()

if toMatch==permHash:
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')

0 comments on commit 5096bf0

Please sign in to comment.