This question was also discussed in class. Review the slides (see above) prior t
ID: 3697294 • Letter: T
Question
This question was also discussed in class. Review the slides (see above) prior to working on this problem. The problem is essentially an encoding/decoding problem losely based on the German Enigma machine used during WWII. This is the code that Allan Turing and his colleagues broke. The movie "The Imitation Game" gives a fairly good historical account of this enterprise.
For this problem you pick a 3-letter English word and encode each letter in the 3-letter word randomly, using one of the 26 letters of the alphabet.All of the encoded 3 letters may be the same as the original. Use this MS-Word file for more detailed instructions FinalExamCodeProblem.docx [Preview the document] [View in a new window]
Requirement:
1. You pick the word you want to encode. Show the word in a small window labeled "original word" (this is not user input. it is only for showing the word you picked).
2. Make two more small windows. One where you show the encoded word and another where you show thedecoded word so it can be compared to the original.
3. Have a simple GUI with an encode button to start the program and a decode button to decode
4. Print the the encoded word after the encode button is pushed and print the decoded word when the decode button is pushed and the program terminates..
5. Write a timer that measures the number of milliseconds it took to decode. (you may use a window for that as well)
JAVA Encoder and code breaker.
Instructions:
First do some background reading on the Enigma machine, using the links below. Be sure to try the Enigma simulator and watch the videos to get a feel for the complexity of the encoding that Enigma was capable of.
http://www.quora.com/How-did-Alan-Turing-figure-out-the-Enigma-machine
http://enigma.louisedade.co.uk/index.html
Next you will develop an encoder in JAVA
Write down some English 3-letter word.
Here are some Examples: Get, sun, and, can, saw, dog, one, two, six, old, ten, for, you, end.
Type a few of these 3-letter words into the Enigma simulator.
Next design a JAVA program that does the following:
It allows the user to input a three letter word.
It saves this word in an array / string.
Then the program randomly picks a letter from the 26 letters of the alphabet and uses that letter to replace the first letter of the 3-letter word.
The program checks if the randomly selected letter matches the first letter of the 3-letter word. If it does not, the program proceeds to the next letter and replaces it with a letter randomly selected from the 26 letters of the alphabet;
If the randomly selected letter matches the first letter of the 3-letter word, the program randomly selects another letter and repeats that process until the randomly selected letter is different from the first letter of the 3-letter word.
The same process is repeated for the next two letters of the 3-letter word.
At this point you have an encoded 3-letter word. For example let us say the original word was “dog” (without the quotes. This could have been encoded variously as: mii, laz, fqy, zlp.
Save the encoded “word”.
Remember: A copy of the original word must also be saved.
Now comes the fun part: Write code that does the following:
For the first letter of the encoded word, each of the 26 letters of the alphabet is substituted. This would yield 26 3-letter strings. Check if any of the 3-letter strings (words) thus generated match the original word that was encoded.
Now, for each of the 26 3-letter strings, take the second letter and substitute each of the 26 letters of the alphabet. You now have made substitutions for the first two letters in the encoded 3-letter word. This would yield 26 * 26, or 626 new 3-letter strings (words). Check if any of the 3-letter words thus generated match the original that was encoded.
Explanation / Answer
import javax.xml.bind.DatatypeConverter; public class f{ public static void main(String a[]){ String str = new String(DatatypeConverter.parseBase64Binary("user:123")); String res = DatatypeConverter.printBase64Binary(str.getBytes()); System.out.println(res); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.