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
|
!/usr/bin/env python
|
||||||
|
|
||||||
https://pypi.org/project/websockets/
|
https://pypi.org/project/websockets/
|
||||||
|
|
||||||
@author Lachezar Todorov
|
@author Lachezar Todorov
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import encrypt_decrypt
|
import encrypt_decrypt
|
||||||
|
|
||||||
from websockets import connect
|
from websockets import connect
|
||||||
|
|
||||||
class Alice():
|
class Alice():
|
||||||
async def messageEncrypt(uri, publicKey, message):
|
async def messageEncrypt(uri, publicKey, message):
|
||||||
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"))
|
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
|
!/usr/bin/env python
|
||||||
|
|
||||||
https://pypi.org/project/websockets/
|
https://pypi.org/project/websockets/
|
||||||
|
|
||||||
@author Lachezar Todorov
|
@author Lachezar Todorov
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import encrypt_decrypt
|
import encrypt_decrypt
|
||||||
from websockets import serve
|
from websockets import serve
|
||||||
|
|
||||||
class Bob():
|
class Bob():
|
||||||
async def decrypt(websocket, path, privateKey):
|
async def decrypt(websocket, path, privateKey):
|
||||||
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)
|
||||||
|
|
||||||
async def main(privateKey):
|
async def main(privateKey):
|
||||||
async with serve(Bob.decrypt, "localhost", 8765, privateKey):
|
async with serve(Bob.decrypt, "localhost", 8765, privateKey):
|
||||||
await asyncio.Future() # run forever
|
await asyncio.Future() # run forever
|
||||||
|
|
||||||
#asyncio.run(main())
|
#asyncio.run(main())
|
Loading…
Reference in New Issue
Block a user