Skip to content
Snippets Groups Projects
Commit 9cdadfa6 authored by jo2-holdsworth's avatar jo2-holdsworth
Browse files

part 2

parent b5008380
No related branches found
No related tags found
No related merge requests found
tree = "-ETIANMSURWDKGOHVF*L*PJBXCYZQ**54*3*¿?2&*+****16=/***(*7***8*90*************_****\"**.********'**-********;!*)***¡*,****:****************$***********************************************************************************************************************"
def decode(string):
output = ""
parent = 1
for i in range(len(string)):
if i < len(string) - 1 :
if string[i] == " ":
output += tree[parent - 1]
parent = 1
if string[i] == ".":
parent = 2 * parent
elif string[i] == "-":
parent = 2 * parent + 1
else:
if string[i] == ".":
parent = 2 * parent
if string[i] == "-":
parent = 2 * parent + 1
output += tree[parent - 1]
parent = 1
return output
print(decode(".-. .---- -.. . ... .---- -...- .... .. -...- -.--."))
\ No newline at end of file
# encode_ham(sender: str, receiver: str, msg:str) -> str
import morse
import server
import asyncio
def encode_ham(sender, receiver, msg):
output = receiver + "de" + sender + "=" + msg + "=("
# print(output)
return morse.encode(output)
def decode_ham(str2):
print("hi")
ret = morse.decode(str2)
sender = ret.split("DE")
receiver = sender[1].split("=")
msg = receiver[1].split("=(")
return (sender[0],receiver[0],msg[0])
# print(encode_ham("jack","echo","its me"))
print(encode_ham("s","echo","msg"))
asyncio.run(server.main(encode_ham("jack","time","hello world")))
print(decode_ham(asyncio.run(server.main(encode_ham("jack","echo","hello how are you")))))
# print(decode_ham(".-. .---- -.. . ... .---- -...- .... .. -...- -.--."))
\ No newline at end of file
tree = "-ETIANMSURWDKGOHVF*L*PJBXCYZQ**54*3*¿?2&*+****16=/***(*7***8*90*************_****\"**.********'**-********;!*)***¡*,****:****************$***********************************************************************************************************************"
output = ""
for item in tree:
output += "\"" + item + "\"" + ","
print(output)
\ No newline at end of file
tree = "-ETIANMSURWDKGOHVF*L*PJBXCYZQ**54*3***2**+****16=/*****7***8*90"
def decode(string):
global tree
output = ""
parent = 1
for i in range(len(string)):
if i < len(string) - 1 :
if string[i] == " ":
output += tree[parent - 1]
parent = 1
if string[i] == ".":
parent = 2 * parent
elif string[i] == "-":
parent = 2 * parent + 1
else:
if string[i] == ".":
parent = 2 * parent
if string[i] == "-":
parent = 2 * parent + 1
output += tree[parent - 1]
parent = 1
return output
def add(string,addString):
global tree
string = string.replace(" ", "")
print(pow(2,len(string))*2)
print(len(tree))
if len(tree) <= (pow(2,len(string)*2)):
for i in range(pow(2,len(string))*2 - len(tree)):
tree = tree + "*"
output = ""
parent = 1
for i in range(len(string)):
if i < len(string) - 1 :
if string[i] == ".":
parent = 2 * parent
elif string[i] == "-":
parent = 2 * parent + 1
else:
if string[i] == ".":
parent = 2 * parent
if string[i] == "-":
parent = 2 * parent + 1
output = tree[:parent-1] + addString + tree[parent:]
tree = output
print(output)
parent = 1
print(decode(string))
if decode(string) != addString:
print("error, insert fail")
return output
# print(decode(".-. .---- -.. . ... .---- -...- .... .. -...- -.--."))
print(add(".-.-.-","."))
print(add("-.--.","("))
print(add(".-.-.","+"))
print(add("..-.- ","¿"))
print(add("--..-- ",","))
print(add("-.--.-",")"))
print(add("-....-","-"))
print(add("--...-","¡"))
print(add("..--.","?"))
print(add(".-...","&"))
print(add("..--.- ","_"))
print(add(".----.","'"))
print(add("---...",":"))
print(add(".-..-. ",'"'))
print(add("-.-.--","!"))
print(add("-.-.-.",";"))
print(add("...-..-","$"))
...@@ -86,7 +86,8 @@ class node: ...@@ -86,7 +86,8 @@ class node:
return "" return ""
def initTree(): def initTree():
alphabet = ["E","T","I","A","N","M","S","U","R","W","D","K","G","O","H","V","F","","L","","P","","J","B","X","C","Y","Z","Q","",""] # alphabet = ["E","T","I","A","N","M","S","U","R","W","D","K","G","O","H","V","F","","L","","P","","J","B","X","C","Y","Z","Q","",""]
alphabet = ["E","T","I","A","N","M","S","U","R","W","D","K","G","O","H","V","F","*","L","*","P","J","B","X","C","Y","Z","Q","*","*","5","4","*","3","*","¿","?","2","&","*","+","*","*","*","*","1","6","=","/","*","*","*","(","*","7","*","*","*","8","*","9","0","*","*","*","*","*","*","*","*","*","*","*","*","*","_","*","*","*","*","\"","*","*",".","*","*","*","*","*","*","*","*","'","*","*","-","*","*","*","*","*","*","*","*",";","!","*",")","*","*","*","¡","*",",","*","*","*","*",":","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","$","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*","*"]
queue = [] queue = []
start = node("start") start = node("start")
......
import asyncio
import websockets
import json
import time
async def main(str):
uri = "ws://localhost:10102"
async with websockets.connect(uri) as websocket:
# After joining server will send client unique id.
message = json.loads(await websocket.recv())
print(message)
# Get the client_id from the join message
if message['type'] == 'join_evt':
client_id = message['client_id']
# Send a ping to the server
await send_message(websocket, str, client_id)
# Wait for the 'ping' response from the server
response = await recv_message(websocket)
print("The Server Sent Back:")
print(response)
else:
# If first message is not the join message exit
print("Did not receive a correct join message")
return 0
return response
async def send_message(websocket, message, client_id):
outward_message = {
'type' : 'morse_evt',
'client_id': client_id,
'payload': message
}
await websocket.send(json.dumps(outward_message))
async def recv_message(websocket):
message = json.loads(await websocket.recv())
return message['payload']
if __name__ == "__main__":
print("Echo client")
while 1:
time.sleep(1)
asyncio.run(main())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment