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:
parent
2b1f25e131
commit
b9cf6dc6b5
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
src/py-cli/encrypt_decrypt.py
Normal file → Executable file
0
src/py-cli/encrypt_decrypt.py
Normal file → Executable file
0
src/py-cli/main.py
Normal file → Executable file
0
src/py-cli/main.py
Normal file → Executable file
42
src/py-cli/websock/alice.py
Normal file → Executable file
42
src/py-cli/websock/alice.py
Normal file → Executable 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
46
src/py-cli/websock/bob.py
Normal file → Executable 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())
|
Loading…
Reference in New Issue
Block a user