From 5096bf019cfcae0783dd75e13dfd9cbcf3f290d6 Mon Sep 17 00:00:00 2001 From: pranav1812 Date: Thu, 23 Apr 2020 08:17:41 +0530 Subject: [PATCH] first commit --- projectFile.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ projectFile2.py | 19 +++++++++++++++++++ solution.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 projectFile.py create mode 100644 projectFile2.py create mode 100644 solution.py diff --git a/projectFile.py b/projectFile.py new file mode 100644 index 0000000..d8c928a --- /dev/null +++ b/projectFile.py @@ -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 \n int main(){ \nprintf("this is flag: '+str(j)+' "); \n} ' ) + file.close() + os.chdir('..') +print(os.path.abspath(path)) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/projectFile2.py b/projectFile2.py new file mode 100644 index 0000000..eb1b0ba --- /dev/null +++ b/projectFile2.py @@ -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') \ No newline at end of file diff --git a/solution.py b/solution.py new file mode 100644 index 0000000..81c6be9 --- /dev/null +++ b/solution.py @@ -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') \ No newline at end of file