Difference between revisions of "Top Secret"

From CompSciWiki
Jump to: navigation, search
Line 7: Line 7:
 
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','.','!',' '};<br />
 
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','.','!',' '};<br />
 
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'};
 
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'};
 +
 +
<br \><br \>
  
 
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 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.
Line 16: Line 18:
  
  
The output will be simple.  The program will print out the mission. (Or self destruct, but you should run away before that happens)<br \>
 
<pre>
 
Array: "word1" "word2" "word3"
 
It is ordered.
 
Guess 1: blah
 
Guess 2: blah
 
Guess 3: word1
 
 
The array contains "word1".
 
It took you 3 attempt(s) to get it.
 
</pre>
 
  
 
|SideSectionTitle=Problem Solving and Programming Examples
 
|SideSectionTitle=Problem Solving and Programming Examples

Revision as of 19:38, 8 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