Math Bonanza
Author: PewZ
Can you answer 1000 math questions?
nc math.tghack.no 10000
# -*- coding:utf-8 -*-import socketimport sysdef solve(s):a = s.split(' ')if a[1] == '+':return int(a[0]) + int(a[2])elif a[1] == '-':return int(a[0]) - int(a[2])elif a[1] == '*':return int(a[0]) * int(a[2])elif a[1] == '/':return int(a[0]) / int(a[2])host = 'math.tghack.no'if len(sys.argv) > 1:host = sys.argv[1]port = 10000if len(sys.argv) > 2:host = int(sys.argv[2])client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)client.connect((host, port))client_file = client.makefile('b')while True:s = client.recv(100)print(s)if 'TG19{' in s:sys.exit(1)a = s.split('\n')for i in range(len(a)):if 'Level' in a[i]:ans = solve(a[i + 1])print(ans)client_file.write(str(ans) + "\n")client_file.flush()break
実行すると次のようになります。
(略)Level 998/1000245 - 149Answer:96Yay!Level 999/100040 / 1Answer:40Yay!TG19{calculate_all_the_things}
フラグは、
TG19{calculate_all_the_things}