From 9bd87725d3c92252fedb2478cebc6f219ae07a2d Mon Sep 17 00:00:00 2001 From: Lachezar Todorov Date: Sun, 17 Oct 2021 18:15:12 -0400 Subject: [PATCH] Made some improvements to the readability of the code and changed it to that Bob just prints the decrypted message rather than sending it to Alice to print it --- src/py-cli/main.py | 1 + src/py-cli/websock/alice.py | 4 ++-- src/py-cli/websock/bob.py | 15 +++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/py-cli/main.py b/src/py-cli/main.py index f54e232..7f2ec33 100755 --- a/src/py-cli/main.py +++ b/src/py-cli/main.py @@ -13,6 +13,7 @@ def main(): key_length = 512 + #Bob's keys publicKey, privateKey = encrypt_decrypt.encrypt_decrypt.make_keys(key_length) asyncio.run(websock.alice.Alice.messageEncrypt("ws://localhost:8765", publicKey, message)) diff --git a/src/py-cli/websock/alice.py b/src/py-cli/websock/alice.py index 6704e39..bad5596 100755 --- a/src/py-cli/websock/alice.py +++ b/src/py-cli/websock/alice.py @@ -16,7 +16,7 @@ class Alice(): encryptedMessage = encrypt_decrypt.encrypt_decrypt.encryption(message, publicKey) async with connect(uri) as websocket: await websocket.send(encryptedMessage) - message = await websocket.recv() - print(message) + #message = await websocket.recv() + #print(message) #asyncio.run(hello("ws://localhost:8765")) \ No newline at end of file diff --git a/src/py-cli/websock/bob.py b/src/py-cli/websock/bob.py index 9cf6b87..a566bf3 100755 --- a/src/py-cli/websock/bob.py +++ b/src/py-cli/websock/bob.py @@ -11,14 +11,21 @@ import encrypt_decrypt from websockets import serve class Bob(): - async def decrypt(websocket, path, privateKey): + def __init__(self,privateKey): + self.pk = privateKey + + async def decrypt(websocket, path): + privateKey = "" #dummy variable to make code work, please change! async for message in websocket: message = await websocket.recv() decryptedMessage = encrypt_decrypt.encrypt_decrypt.decryption(message, privateKey) - await websocket.send(decryptedMessage) + #await websocket.send(decryptedMessage) + print(decryptedMessage) - async def main(privateKey): - async with serve(Bob.decrypt, "localhost", 8765, privateKey): + async def messageDecrypt(privateKey): + #do something with privateKey to send it to decrypt + + async with serve(Bob.decrypt, "localhost", 8765): await asyncio.Future() # run forever #asyncio.run(main()) \ No newline at end of file