Difference between revisions of "Top Secret"

From CompSciWiki
Jump to: navigation, search
(Fixed some formatting and a typo in problem statement)
(Split the char arrays and secret message in the code onto 2 lines so the page doesn't scroll horizontally as much)
Line 30: Line 30:
 
public static void main(String [] args)
 
public static void main(String [] args)
 
{
 
{
char [] array1 = {'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','.','!',' '};
+
char [] array1 = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
char [] array2 = {'l','x','g','r','j','w','!','i','q','a','t','z','.','s','y','k','e','o',' ','p','d','c','h','n','v','u','f','b','m'};
+
                                  'q','r','s','t','u','v','w','x','y','z','.','!',' '};
String secretMessage = "lpoyjkhmj sjygporjoplmhksdy.s.hjlzomrghljowqjxhyrdomlhhqspyismh.llosrvpmypsqj.hxjqopl ";
+
char [] array2 = {'l','x','g','r','j','w','!','i','q','a','t','z','.','s','y','k',
 +
                                  'e','o',' ','p','d','c','h','n','v','u','f','b','m'};
 +
String secretMessage = "lpoyjkhmj sjygporjoplmhksdy.s.hjlzomrghljow
 +
                                        qjxhyrdomlhhqspyismh.llosrvpmypsqj.hxjqopl ";
  
 
String start = "top secret";
 
String start = "top secret";

Revision as of 14:40, 9 April 2010

Back to the Program-A-Day homepage

Problem

You are a software developer for CSIS (Canadian Security Inteligence Service) and you've been sent a secret message, but all of the software at your station has been deleted! However, this message is very important and must be decoded right away. That's where you come in. You will write a program that decodes the message, verifies the authenticity, then prints out the mission directive.

First, the message is in a secret code. Every character is represented by a different character. The following arrays show the relationship. The first one is our alphabet, the second is the secret one.

char [] array1 = {'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','.','!',' '};
char [] array2 = {'l','x','g','r','j','w','!','i','q','a','t','z','.','s','y','k','e','o',' ','p','d','c','h','n','v','u','f','b','m'};



Once you've decoded the message, you'll have to verify it. Every other character, starting with the first character, if put together, will form a palindrome. You must write two methods: one that will form the palindrome out of the message, the other method to make sure that it is indeed a palindrome.

Once you've verified that, there is one last check. The message must start with the phrase "top secret". If not, it's a fake! After you've determined that the message is the real deal, you have to print out just the mission instruction. (Use substring to print out the message after the "top secret" part)

 

Problem Solving and Programming Examples

Wiki bench01.jpg

Solution



Code

Solution Code

Back to the Program-A-Day homepage