diff --git a/projects/Morse Code Encoder & Decoder/morse_code.py b/projects/Morse Code Encoder & Decoder/morse_code.py new file mode 100644 index 00000000..546aa264 --- /dev/null +++ b/projects/Morse Code Encoder & Decoder/morse_code.py @@ -0,0 +1,69 @@ +codes = { + "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":"-----", +} + +def encode_text(t): + encoded_message = "" + + for i in range(len(t)): + encoded_message += t[i] + ' ' + + return encoded_message + + +def decode_morse_code(c): + decoded_message = "" + c = c.split(" ") + + for i in range(len(c)): + for key, value in codes.items(): + if c[i] == value: + decoded_message += key + + return decoded_message + + + +selector = int(input("1-> Encode | 2-> Decode: ")) + +if(selector == 1): + print(encode_text(input("Enter text: ").lower())) + +else: + print(decode_morse_code(input("Enter morse code: "))) \ No newline at end of file diff --git a/projects/Morse Code Encoder & Decoder/readme.md b/projects/Morse Code Encoder & Decoder/readme.md new file mode 100644 index 00000000..545ac0eb --- /dev/null +++ b/projects/Morse Code Encoder & Decoder/readme.md @@ -0,0 +1,17 @@ +# Morse Code Encoder and Decoder + +## Description + +