cryptoSL2024/alice.py
Robert Bendun 657eea8fc1 networking
2024-04-18 00:09:59 +02:00

31 lines
898 B
Python

import argparse
import socket
import contextlib
from otp import alice
from net import send, send_point, recv, recv_point
def main():
p = argparse.ArgumentParser()
p.add_argument('msg0', help='First file which Bob can receive')
p.add_argument('msg1', help='Second file which Bob can receive')
p.add_argument('-p', '--port', type=int, default=8080)
args = p.parse_args()
with open(args.msg0, 'rb') as f0, open(args.msg1, 'rb') as f1:
m0 = f0.read()
m1 = f1.read()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('0.0.0.0', args.port))
s.listen(1)
bob, address = s.accept()
ip, _ = address
a = alice(m0, m1)
send_point(bob, a.send(None))
send(bob, a.send(recv_point(bob)))
if __name__ == "__main__":
main()