Level: Beginner
Focus: Loops, Switch statement, Scanner object
Encoded First Line Question
Ever thought of becoming a spy? No, me neither. Still, I always liked the part about passing secret messages from one person to another. In this exercise you will need to write a decoding program to be able to answer the question.
I'm looking for a simple solution that takes a line of encoded text entered by the user and uses a combination of a normal for loop and switch statement to decode it. Finally, it will display the decoded text to the user.
The code is a simple letter switch as outlined in the table below. For example, the name "bob" becomes "rdr" (i.e., b=r, o=d, b=r). Don't worry about capital letters, just assume that all of the text is in lowercase.
The question is can your program decode this first line from a book by Iain Banks?
xv fpu vot ipk nk chpwindvoth tqeyditi
To get the most out of this question try and figure out the answer before coming back to read the solution on the next page.
| Decoded | a | b | c | d | e | f | g | h | i | j | k | l | m |
| Encoded | p | r | j | i | t | g | c | o | x | b | s | y | n |
| Decoded | n | o | p | q | r | s | t | u | v | w | x | y | z |
| Encoded | w | d | e | m | h | u | v | l | z | f | q | k | a |

