Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
from subprocess import *
import socket
import re
# http://doloopwhile.hatenablog.com/entry/20111216/1323985472
import romannum
#https://github.com/sumginazu/dormsaver/blob/master/WordsToNumbers.py
import WordsToNumbers
wtn = WordsToNumbers.WordsToNumbers()
HOST = "ctfquest.trendmicro.co.jp"
PORT = 51740
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
q = ""
while True :
q += s.recv(1)
if q[-1] == '=' :
q = q[:-1]
#question
print q + "=",
#remove ","
q = q.replace(',', '')
#make translate table
words1 = filter(lambda w: len(w) > 0, [x.strip() for x in re.split(r'\+|\-|\,|\.|\*|\(|\)|\=', q)])
kv = {}
for word in words1:
try :
# roman num -> nomal num
num = test2.roman_to_int(word)
kv[word]=num
except :
try :
# english num -> nomal num
num = wtn.parse(word)
kv[word]=num
except :
pass
#translate
for (k, v) in sorted(kv.items(), key=lambda x: -len(x[0])) :
q = q.replace(k, str(v))
p = Popen(["bc"], stdin=PIPE, stdout=PIPE)
p.stdin.write(q+'\n')
a = ""
while True :
a += p.stdout.read(1)
if a[-1] == '\n' :
s.send(a[:-1]+'\r\n')
#answer
print a[:-1]
break
string = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment