#K67727. Morse Code Encryption and Decryption
Morse Code Encryption and Decryption
Morse Code Encryption and Decryption
This problem requires you to implement two functionalities: encryption and decryption of messages using Morse code.
Given an input command (either "ENCRYPT" or "DECRYPT") and a subsequent string, your task is to convert the string into its Morse code representation or decode a Morse code back to plain text.
The Morse code mapping is defined for lowercase English letters and digits. In the encryption process, each letter is converted to its Morse equivalent, with a single space separating Morse codes of characters and the delimiter /
(surrounded by spaces) separating words. In decryption, the process is reversed.
For example, the Morse code for (a) is ( .- ) and the encryption of "hello world" is
(.... . .-.. .-.. --- / .-- --- .-. .-.. -..).
inputFormat
The input consists of two lines read from standard input (stdin).
The first line contains a command: either ENCRYPT
or DECRYPT
.
The second line contains the string to be processed.
For encryption, the string consists of lowercase letters, digits, and spaces. For decryption, the string is a valid Morse code, where letters are separated by a single space and words are separated by ' / '.
outputFormat
Output the resulting string to standard output (stdout) after performing the specified conversion.
If the command is ENCRYPT
, output the Morse code representation of the input text.
If the command is DECRYPT
, output the plain text message decoded from the Morse code.## sample
ENCRYPT
hello world
.... . .-.. .-.. --- / .-- --- .-. .-.. -..