Skip to content

Instantly share code, notes, and snippets.

@minhtt159
Last active November 19, 2017 18:47
Show Gist options
  • Save minhtt159/6bb01847842a031ab40fdee3e5a21107 to your computer and use it in GitHub Desktop.
Save minhtt159/6bb01847842a031ab40fdee3e5a21107 to your computer and use it in GitHub Desktop.
SvATTT2017 - Onion
file = open('solveme.txt','r').read().split('\n')
enlarge = 0x636f
def brute(line, goal):
# print line, goal
for x in range(0,512):
for y in range(0,512):
t_x = x + enlarge
t_y = y + enlarge
result = 0
for i in range(0,len(line),2):
symbol = line[i]
coeff,_x,_y = [int(k) for k in line[i+1]]
# print symbol, coeff,x,_x,y,_y
if symbol == '+':
result += coeff*(t_x**_x)*(t_y**_y)
elif symbol == '-':
result -= coeff*(t_x**_x)*(t_y**_y)
else:
print 'error'
if result == goal:
return (x,y)
return (-1,-1)
for xx in range(len(file)):
line = file[xx].split()
_len = len(line)
result = 0
board = ['+']
if _len == 0:
continue
for i in range(_len):
if line[i] == '==':
continue
if i == _len-1:
result = int(line[i])
break
if i%2 == 0:
temp = line[i].split('*')
coeff, x, y = 0,0,0
if len(temp) == 3:
coeff, x, y = temp
elif 'x' in line[i]:
coeff, x = temp
else:
coeff, y = temp
try:
x = x.split('^')[1]
except:
pass
try:
y = y.split('^')[1]
except:
pass
board += [(coeff,x,y)]
else:
board += [line[i]]
print brute(board, result)
ss = [361, 293, 84, 138, 197, 419, 189, 404, 216, 177, 383, 432, 344, 366, 87, 273, 419, 229, 254, 225, 349, 438, 140, 205, 107, 498, 163, 249, 206, 220, 105, 311, 315, 475, 44, 55, 355, 261, 434, 216, 249, 303, 60, 150, 493, 19, 291, 297, 184, 220, 206, 360, 303, 218, 301, 390, 343, 411, 420, 416, 70, 288, 400, 335]
size = 9
def reverse(byte, n):
return (byte<<n)%(1<<size)|(byte>>(size-n))
flag = ''
for i in range(len(ss)-1):
ss[i] = reverse(ss[i],(i+3) % size)
ss[i] = reverse(ss[i],i % size)
flag += bin(ss[i])[2:].zfill(9)
print hex(int(flag,2))[2:-1].decode('hex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment