Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import socket
  2.  
  3. host = 'maidakectf2019.aokakes.work'
  4. port = 17270
  5.  
  6. client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7. client.connect((host, port))
  8.  
  9. # 余計な文字は予め取得しておく
  10. client.recv(64).decode()
  11.  
  12. def calc(problem):
  13. if problem[1] == '+':
  14. return str(int(problem[0]) + int(problem[2]))
  15. elif problem[1] == '-':
  16. return str(int(problem[0]) - int(problem[2]))
  17. elif problem[1] == '*':
  18. return str(int(problem[0]) * int(problem[2]))
  19. elif problem[1] == '/':
  20. return str(int(problem[0]) // int(problem[2]))
  21.  
  22.  
  23. if __name__ == '__main__':
  24.  
  25. while True:
  26. res = client.recv(1024).decode()
  27. print(res)
  28.  
  29. if not 'MaidakeCTF' in res:
  30. problem = res.split()
  31. ans = calc(problem)
  32. print(ans)
  33. client.send(ans.encode())
  34. else:
  35. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement