wooly-vault/solutions/2.py

34 lines
628 B
Python

from io import BufferedRWPair
import socket
REMOTE = "127.0.0.1"
PORT = 1338
def main() -> int:
s = socket.socket()
s.connect((REMOTE, PORT))
sf: BufferedRWPair = s.makefile('rwb')
pl = int.to_bytes(1337, 2, "big")
_ = send(sf, pl)
_ = recv(sf).decode()
sf.close()
return 0
def send(sf: BufferedRWPair, msg: bytes) -> int:
print(f"> {msg.hex()}")
sent: int = sf.write(msg + b"\n")
sf.flush()
return sent
def recv(sf: BufferedRWPair) -> bytes:
response = sf.readline().strip()
print(f"< {response}")
return response
if __name__ == "__main__":
exit(main())