Monday's Programming 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. This week you will need to write a decoding program to be able to answer my 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, display the decoded text to the user.
The code is a simple letter switch:
| 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 |
The question is can your program decode this first line from a book by Iain Banks?
xv fpu vot ipk nk chpwindvoth tqeyditi


For example, the name “bob” becomes “joj” (i.e., b=j, o=h, b=j). Don’t worry about capital letters, just assume that all of the text is in lowercase.
BOB becomes JHJ am i right??
hey Jose, good spot – unfortunately it turns out that I put the coded and encoded letters around the wrong way *embarrassed cough* – “bob” does in fact become “rdr”.
Here’s the C++ version of the puzzle:
http://codepad.org/NrdY3fHZ
/**
*
* @author james
* 9/29/2009
*/
public class Decode {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String ar[]= {”x”,”v”,” “,”f”,”p”,”u”,” “,”v”,”o”,”t”,” “,”i”,”p”,”k”,” “,”n”,”k”,” “,”c”,”h”,”p”,”w”,”i”,”n”,”d”,”v”,”o”,”t”,”h”,” “,”t”,”q”,”e”,”y”,”d”,”i”,”t”,”i”};
String Encoded[] = {”p”,”r”,”j”,”i”,”t”,”g”,”c”,”o”,”x”,”b”,”s”,”y”,”n”,”w”,”d”,”e”,”m”,”h”,”u”,”v”,”l”,”z”,”f”,”q”,”k”,”a”,” “};
String Decoded[] = {”a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”,” “};
int a=0;
String Decode[] = new String[ar.length];
while(a
the code is in java
public class Decoding {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String text = new String(”xv fpu vot ipk nk chpwindvoth tqeyditi.”);
char array[];
array = text.toCharArray();
//System.out.println(array.length + ” ” + array[0]);
for (int i = 0; i