Made Alice and Bob classes. Alice encrypts a message and sends it to Bob, who decrypts the message and should print the plaintext to show he decrypted it. However, that is not the case.

This commit is contained in:
Lachezar Todorov 2021-10-17 17:38:16 -04:00
parent 2b1f25e131
commit b9cf6dc6b5
7 changed files with 44 additions and 44 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
src/py-cli/encrypt_decrypt.py Normal file → Executable file
View File

0
src/py-cli/main.py Normal file → Executable file
View File

42
src/py-cli/websock/alice.py Normal file → Executable file
View File

@ -1,22 +1,22 @@
"""
!/usr/bin/env python
https://pypi.org/project/websockets/
@author Lachezar Todorov
"""
import asyncio
import encrypt_decrypt
from websockets import connect
class Alice():
async def messageEncrypt(uri, publicKey, message):
encryptedMessage = encrypt_decrypt.encrypt_decrypt.encryption(message, publicKey)
async with connect(uri) as websocket:
await websocket.send(encryptedMessage)
message = await websocket.recv()
print(message)
"""
!/usr/bin/env python
https://pypi.org/project/websockets/
@author Lachezar Todorov
"""
import asyncio
import encrypt_decrypt
from websockets import connect
class Alice():
async def messageEncrypt(uri, publicKey, message):
encryptedMessage = encrypt_decrypt.encrypt_decrypt.encryption(message, publicKey)
async with connect(uri) as websocket:
await websocket.send(encryptedMessage)
message = await websocket.recv()
print(message)
#asyncio.run(hello("ws://localhost:8765"))

46
src/py-cli/websock/bob.py Normal file → Executable file
View File

@ -1,24 +1,24 @@
"""
!/usr/bin/env python
https://pypi.org/project/websockets/
@author Lachezar Todorov
"""
import asyncio
import encrypt_decrypt
from websockets import serve
class Bob():
async def decrypt(websocket, path, privateKey):
async for message in websocket:
message = await websocket.recv()
decryptedMessage = encrypt_decrypt.encrypt_decrypt.decryption(message, privateKey)
await websocket.send(decryptedMessage)
async def main(privateKey):
async with serve(Bob.decrypt, "localhost", 8765, privateKey):
await asyncio.Future() # run forever
"""
!/usr/bin/env python
https://pypi.org/project/websockets/
@author Lachezar Todorov
"""
import asyncio
import encrypt_decrypt
from websockets import serve
class Bob():
async def decrypt(websocket, path, privateKey):
async for message in websocket:
message = await websocket.recv()
decryptedMessage = encrypt_decrypt.encrypt_decrypt.decryption(message, privateKey)
await websocket.send(decryptedMessage)
async def main(privateKey):
async with serve(Bob.decrypt, "localhost", 8765, privateKey):
await asyncio.Future() # run forever
#asyncio.run(main())