1. Computing & Technology

Discuss in my forum

Encoded First Line

By , About.com Guide

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.

Letter Switch

Decodedabcdefghijklm
Encodedprjitgcoxbsyn
Decodednopqr stuvwx yz
Encodedwdemh uvlzfq ka

©2012 About.com. All rights reserved.

A part of The New York Times Company.