Created
July 24, 2018 16:23
-
-
Save a11ce/625124a74c376607bccd36d1bd6f2031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
HOST = 'unh.w1mem.com' | |
PORT = 25001 | |
def recPrint(s): | |
rec = s.recv(1024) | |
print(rec) | |
return(rec) | |
def main(): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((HOST, PORT)) | |
for _ in range(2): | |
recPrint(sock) | |
sock.send(b"python") | |
recPrint(sock) | |
count = 0 | |
done = False | |
while(not done): | |
q = str(recPrint(sock)) | |
fw = str(q.split(" ")[0]) | |
if( fw == "b'And"): | |
print("un") | |
sock.send(str(count).encode()) | |
recPrint(sock) | |
recPrint(sock) | |
done = True | |
elif(fw == "b'Nice"): | |
sock.send(b"snake") | |
else: | |
count += 1 | |
op1 = int(q.split(" ")[7]) | |
op2 = int(q.split(" ")[9]) | |
res = int(q.split(" ")[11][:-1]) | |
if(op1 + op2 == res): | |
sock.send(b"add") | |
elif(op1 * op2 == res): | |
sock.send(b"mul") | |
elif(op1 - op2 == res): | |
sock.send(b"sub") | |
elif(op1 // op2 == res): | |
sock.send(b"div") | |
recPrint(sock) | |
sock.send(b"MAGIC") | |
recPrint(sock) | |
sock.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment