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

This commit is contained in:
Lachezar Todorov 2021-10-17 18:15:12 -04:00
parent b9cf6dc6b5
commit 9bd87725d3
3 changed files with 14 additions and 6 deletions

View File

@ -13,6 +13,7 @@ def main():
key_length = 512 key_length = 512
#Bob's keys
publicKey, privateKey = encrypt_decrypt.encrypt_decrypt.make_keys(key_length) publicKey, privateKey = encrypt_decrypt.encrypt_decrypt.make_keys(key_length)
asyncio.run(websock.alice.Alice.messageEncrypt("ws://localhost:8765", publicKey, message)) asyncio.run(websock.alice.Alice.messageEncrypt("ws://localhost:8765", publicKey, message))

View File

@ -16,7 +16,7 @@ class Alice():
encryptedMessage = encrypt_decrypt.encrypt_decrypt.encryption(message, publicKey) encryptedMessage = encrypt_decrypt.encrypt_decrypt.encryption(message, publicKey)
async with connect(uri) as websocket: async with connect(uri) as websocket:
await websocket.send(encryptedMessage) await websocket.send(encryptedMessage)
message = await websocket.recv() #message = await websocket.recv()
print(message) #print(message)
#asyncio.run(hello("ws://localhost:8765")) #asyncio.run(hello("ws://localhost:8765"))

View File

@ -11,14 +11,21 @@ import encrypt_decrypt
from websockets import serve from websockets import serve
class Bob(): 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: async for message in websocket:
message = await websocket.recv() message = await websocket.recv()
decryptedMessage = encrypt_decrypt.encrypt_decrypt.decryption(message, privateKey) decryptedMessage = encrypt_decrypt.encrypt_decrypt.decryption(message, privateKey)
await websocket.send(decryptedMessage) #await websocket.send(decryptedMessage)
print(decryptedMessage)
async def main(privateKey): async def messageDecrypt(privateKey):
async with serve(Bob.decrypt, "localhost", 8765, privateKey): #do something with privateKey to send it to decrypt
async with serve(Bob.decrypt, "localhost", 8765):
await asyncio.Future() # run forever await asyncio.Future() # run forever
#asyncio.run(main()) #asyncio.run(main())