kryptografia-semestr-8/serwer.py
Dominik Jagosz bf6aca3918 poczatek
2024-06-18 22:04:24 +02:00

29 lines
1.8 KiB
Python

# https://realpython.com/python-sockets/
# echo-server.py
import socket
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
ip_info = socket.getaddrinfo(socket.gethostname(), PORT)
# print(ip_info)
HOST = ip_info[-1][-1][0]
print(HOST, ":", PORT)
klucz_publiczny_DSA, klucz_prywatny_DSA = (126220152782999491712146716573647923575210663342203877875997463151103734117618780085961998496900968641688295271738389523168262437046367952410100230715977561698699865420228930481833546803155826687224437601550687821059803843460614018330735329864730711512369415813709177511423225057391814747172616206699791431113, 1026153776632400528836961826077414494924816203371, 33135294496110223909298149780807071663246150710874084366253067988796622596843824622279842916377597978486097816392781318387311279773566894876369811406237208448656803682244786284714051489351162528336310611509464319257937304463246532853715133677606472539203807274116025362212599140301963520366587373345549232664, 57789326082328055343244183952945963065038001008054371988423611501774965584951836084636408462704147650194354237953178434916234787575914934345509256412623906774868805317306029570637051066904576874737549979887847806955662502738986630454336931791238784800404714101190106940899556139200869987149012959023189160975) 601201094732353224640534306619895007746271908982
p, q, g, y = klucz_publiczny_DSA
x = klucz_prywatny_DSA
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
conn.send(b"klucz publiczny")
conn.sendall(klucz_publiczny_DSA)
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)