Morse code has existed since the early 1800s and has found its way to the digital era.
What Is Morse Code?
The Morse code gets its name from Samuel Morse, one of the inventors of the telegraph.
you’re free to use thesefree Morse code software and apps to send coded messagesto one another.
To help you get started, here arenine sites to learn Morse codefor free.
Using a dictionary, it’s possible for you to quickly look up any key to its corresponding value.
Declare a function named encrypt that acceptsmessageas an input parameter.
Inside the function, initialize a variable namedcipherwith an empty string.
Youll use this to create and store the encrypted message.
Next, declare a for loop that iterates over each letter in the message.
If the letter is not white space, pass it to the dictionary for lookup.
The dictionary returns the corresponding More code value based on the key.
Declare a function named decrypt that acceptsmessageas an input parameter.
Initialize two variables, decipher, andcitextto hold empty strings.
Iterate a for loop that runs through each letter of the Morse code.
Otherwise, the letter is a space, so increment the counter by one.
Otherwise, jump into the keys using their values.
To do this, iterate over the key-value pairs in dictionary using the items function.
If the citext equals the value, add the corresponding key to the decipher variable using the shorthand operator.
Test the functions with some sample input.
Start by initializing a variable namedmessagewith the word or sentence you want to encrypt.
Morse code contains only uppercase letters, which are the keys in the dictionary.
This also helps avoid unnecessary runtime checks for valid case.
Print the resulting value to view the Morse code equivalent of the original sentence.
Then, store a Morse code in the message variable and pass it to the decrypt function.
Print the result and check that its correct.
This verifies that the translation worked perfectly.
Mobile Applications for Morse Code
Morse code translators are available for free right at your fingertips.
To your surprise, it is even supported by GBoard - the Google Keyboard.
Swipe right through the options, and then choose Morse code.