Question: In outer space, messages sent in space are vulnerable to alteration due to cosmic conditions and interference. To ensure the correctness of messages during transmission,
In outer space, messages sent in space are vulnerable to alteration due to cosmic conditions and interference. To ensure the correctness of messages during transmission, messages need to be encoded in a certain way. In this particular encoding system, characters in a message are followed by a number which indicates how many times the character is to be repeated. However, there's a twist: if the position of the character in the original message is odd the character is repeated one additional time, and if it's even one repetition is subtracted. Your task is to develop a function called CommsDecoder that will take the encoded message as input and return the decoded message to the main program. The main program will read the encoded message, pass it to the function CommsDecoder and print the returned value. Example: For an encoded message HeloH should be repeated times due to its odd positione should be repeated times due to its even positionl should be repeated times due to its odd positiono should be repeated times due to its even position Decoded Message: HHHeellllloooo Instructions Use a while loop to traverse through the message character by character. Depending on the index of the character, adjust the repeat factor and add the repeated character. Assume that the user will always input a character followed by a single digit number, no need for input validation or you can do it for the sake of making it more challenging but it will not affect your grade Sample Run : Enter the encoded message to be sent into space: HLXO Encoded Message: HLXO Decoded Message: HHHHLXXXXXXXXOOOOO Sample Run : Enter the encoded message to be sent into space: INTER Encoded Message: INTER Decoded Message: IIIIINNNNTTTTTTTTEEEERRRR Sample Run : Enter the encoded message to be sent into space: StELLAR Encoded Message: STELLAR Decoded Message: SSSSTEEEEEEELLLAAARRRRRR
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
