Full solution script for Confidence 2019 Teaser
import sys | |
original = [0,0,0,0,0,0,0,0,2 ,0,3,2,1,1,0, 0, | |
0,0,0,0,0,0,0,1,0 ,3,4,2,3,0,0xff,0, | |
0,0,0,0,0,0,1,0,2 ,2,1,3,0,1,0 ,0, | |
0,0,0,0,0,0,0,2,0 ,1,0,0,0,0,0 ,0, | |
0,0,0,0,0,0,0,0,0xfe,0,0,0,0,0,0 ,0] | |
import importlib | |
a=importlib.import_module(sys.argv[1]) | |
import string | |
def solve(): | |
print('#'+str(len(a.solution))) | |
new_sol = [] | |
sol_len = len(a.solution) | |
while sol_len > 0: | |
partial = a.solution[0] | |
if partial in a.solution: | |
a.solution.remove(partial) | |
sol_len = len(a.solution) | |
for c in xrange(0x30,0x7d+1): | |
if chr(c) not in string.digits and chr(c) not in string.ascii_lowercase and chr(c) != '}': | |
continue | |
idx = 72 | |
if original[idx] != 0xfe: | |
break | |
flag = original[:] | |
correct = True | |
p = (c << a.shifts) + partial | |
clone = p | |
for k in range(a.bit_len): | |
b = p & 3 | |
if b == 0: | |
idx -= 17 | |
elif b == 1: | |
idx -= 15 | |
elif b == 2: | |
idx += 15 | |
elif b == 3: | |
idx += 17 | |
if idx < 0: | |
idx += 16 | |
if idx < 0 or idx > len(flag): | |
correct = False | |
if flag[idx] == 0 or flag[idx] == 0xfe: | |
correct = False | |
break #we can't step on zero's | |
flag[idx] -= 1 | |
p >>= 2 | |
if correct:# and idx==30: | |
#print("#[+] Potential successful num: {0:x}".format(clone)) | |
new_sol.append(clone) | |
return new_sol | |
print("bit_len={0}".format(a.bit_len+4)) | |
print("shifts={0}".format(a.shifts+8)) | |
print("solution=["+','.join('{:#04x}'.format(x) for x in solve())+"]") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment