Home / Expert Answers / Computer Science / corey-and-his-friends-have-designed-a-simple-but-unique-method-of-communicating-through-secret-mes-pa875

(Solved): Corey and his friends have designed a simple but unique method of communicating through secret mes ...



Corey and his friends have designed a simple but unique method of communicating through secret messages. To decode a message,Parameter 3: messages - A list of messages to be decoded with each message containing a number of letters separated by spacesSample Input 0
Sample Output 0
\[
\begin{array}{l}
\text { hello } \\
\text { world }
\end{array}
\]
Explanation 0
Given theThe table below shows the mapping of each digit in the new number:
The decoded message is: hello.
Similarly for the message

Corey and his friends have designed a simple but unique method of communicating through secret messages. To decode a message, the recipient must have the encoded message and a key map. The key map assigns each letter to a specific value(or key). A message is decoded by converting each letter, from left to right, to their corresponding value based on the key map, and then from the resulting number take the sum of each consecutive pair of digits (from left to right) to form the digits of a new number. Finally, each digit of this new number must be converted to its corresponding letter to give the original message. Given a key map with pairs of the format for , representing a letter and its key value, decode messages for . Each message is in the format of space-separated letters. Complete the function decode_messages which accepts a dictionary msg_dict with key map, an integer representing the no_of_messages, and the list of messages to be decoded. The function returns a list of the decoded messages without spaces. Input Format Line 1: a single integer . The next lines contain a pair representing letter and its key mapping respectively, for . The next line contains a single integer, . The next lines each contain a string of space-separated letters representing messages. Parameter 1: msg_dict - a dictionary with key map of letter keys and their corresponding integer values Parameter 2: no_of_messages - An integer representing the number of messages to be decoded Parameter 3: messages - A list of messages to be decoded with each message containing a number of letters separated by spaces. Constraints Output Format lines, each line containing a single string(no spaces) representing decoded version of the message. The function returns a list of the decoded messages without spaces. Sample Input 0 Sample Output 0 Explanation 0 Given the message: dhy u y rw u u r The table below shows each letter in the message and its mapping based on the keys given: then we must add all consecutive pairs of digits together from left to right, each pair gives and 9 respectively. The table below shows the mapping of each digit in the new number: The decoded message is: 'hello'. Similarly for the message: w e u h e h d d Adding consecutive pairs of digits together gives the digits and 0 : The decoded message is: 'world'. We return each answer on a separate line as follows: hello world


We have an Answer from Expert

View Expert Answer

Expert Answer


Explanation:Here's the Python code:def decode_messages(msg_dict, no_of_messages, messages): # create a dictionary to map the values to the letters
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe