feat: solutions add solutions for c1-3
cargo devel CI / cargo CI (push) Successful in 1m31s Details

This commit is contained in:
Christoph J. Scherr 2024-09-06 23:55:31 +02:00
parent e5befcc9bf
commit 839206c12a
3 changed files with 63 additions and 1 deletions

30
solutions/1.py Normal file
View File

@ -0,0 +1,30 @@
from io import TextIOWrapper
import socket
REMOTE = "127.0.0.1"
PORT = 1337
def main() -> int:
s = socket.socket()
s.connect((REMOTE, PORT))
sf: TextIOWrapper = s.makefile('rw')
_response: str = recv(sf)
sf.close()
return 0
def send(sf: TextIOWrapper, msg: str) -> int:
print(f"> {msg}")
sent: int = sf.write(f"{msg}\n")
sf.flush()
return sent
def recv(sf: TextIOWrapper) -> str:
response = sf.readline().strip()
print(f"< {response}")
return response
if __name__ == "__main__":
exit(main())

32
solutions/2.py Normal file
View File

@ -0,0 +1,32 @@
from io import BufferedRWPair
import socket
REMOTE = "127.0.0.1"
PORT = 1337
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)
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())

View File

@ -60,7 +60,7 @@ def main() -> int:
s.close()
return 1
s.close()
sf.close()
return 0
def send(sf: TextIOWrapper, msg: str) -> int: