0% found this document useful (0 votes)
9 views

Python MorseCode

Uploaded by

dbqatest001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python MorseCode

Uploaded by

dbqatest001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python_MorseCode.

ipynb - Colab 13/06/24, 3:59 PM

MORSE_CODE = {
'A': '.-',
'B': '-...',
'C': '-.-.',
'D': '-..',
'E': '.',
'F': '..-.',
'G': '--.',
'H': '....',
'I': '..',
'J': '.---',
'K': '-.-',
'L': '.-..',
'M': '--',
'N': '-.',
'O': '---',
'P': '.--.',
'Q': '--.-',
'R': '.-.',
'S': '...',
'T': '-',
'U': '..-',
'V': '...-',
'W': '.--',
'X': '-..-',
'Y': '-.--',
'Z': '--..',
'1': '.----',
'2': '..---',
'3': '...--',
'4': '....-',
'5': '.....',
'6': '-....',
'7': '--...',
'8': '---..',
'9': '----.',
'0': '-----',
'&': '.-...',
'@': '.--.-.',
':': '---...',
',': '--..--',
'.': '.-.-.-',
''': '.----.',
''': '.-..-.',
'?': '..--..',
'/': '-..-.',
'=': '-...-',
https://colab.research.google.com/drive/10VzajFp6K0rzuqJhqs3mR18ZV-qHwXlI Page 1 of 4
Python_MorseCode.ipynb - Colab 13/06/24, 3:59 PM

'=': '-...-',
'+': '.-.-.',
'-': '-....-',
'(': '-.--.',
')': '-.--.-',
'!': '-.-.--',
}

def encrypt(message):
return ' '.join(
[
MORSE_CODE[char.upper()] if char != ' ' else '/'
for char in message
]
)

sList = []

def decrypt(dMessage):
decryptM = ''

sList = dMessage.split(' ')

for i in sList:
if i == '/':
decryptM += ' '
else:
for key, value in MORSE_CODE.items():
if value == i:
decryptM += key

return decryptM

print(decrypt('.--. -.-- - .... --- -. / ...-- .-.-.- ----. '))

PYTHON 3.9

dMessage = '.--. -.-- - .... --- -. / ...-- .-.-.- ----. '


sList = dMessage.split(' ')
print(sList)

['.--.', '-.--', '-', '....', '---', '-.', '/', '...--', '.-.-.-', '----.', ''

https://colab.research.google.com/drive/10VzajFp6K0rzuqJhqs3mR18ZV-qHwXlI Page 2 of 4
Python_MorseCode.ipynb - Colab 13/06/24, 3:59 PM

MORSE_CODE = {
'A': '.-',
'B': '-...',
'C': '-.-.',
'D': '-..',
'E': '.'
}

sList = []
decryptM = ''

def decrypt(dMessage):
sList = dMessage.split(' ')

for i in sList:
if i != ' ':
for key, value in MORSE_CODE.items():
if value == ".-":
decryptM += key
elif i == '/':
decryptM += ' '

return decryptM

# MorseCode.encrypt('HOLD!')
# '.... --- .-.. -.. -.-.--'

# MorseCode.decrypt('.... --- .-.. -.. -.-.--')


# 'HOLD!'

https://colab.research.google.com/drive/10VzajFp6K0rzuqJhqs3mR18ZV-qHwXlI Page 3 of 4
Python_MorseCode.ipynb - Colab 13/06/24, 3:59 PM

https://colab.research.google.com/drive/10VzajFp6K0rzuqJhqs3mR18ZV-qHwXlI Page 4 of 4

You might also like