OverviewAn important class of algorithms that some computer scientist concern themselves with are encryption and decryption techniques. How can text be encoded so that no one can read it apart from the desired recipient? This is critical for trade secrets and government messages, but even more critical for such common needs as secure web-based purchases, being able to send your password over the web without others listening in, and so on. An old simplistic trick is the rotation cipher. Pick a key from 1 and 25; then for each character in your message, shift each letter forward by the key, wrapping around the end of the alphabet. For example, if your original message is "hi how are you", and your key is 2, your encrypted message is "jk jqy ctg aqw". Supposedly, Julius Caesar used this technique to communicate with his generals. Your assignmentCreate a directory called rotation. You will actually write two programs. The first one, called Encoder.java, should read a message in English contained in a file called source.txt. Your program should assume that your input text is entirely in lower case, with no punctuation. Encoder.java should pick a key from 1 to 25 at random and encode your message, printing it out to the screen. Your second program, called Decoder.java, should read an encrypted message from a file called encrypted.txt. Your program should assume that your encrypted text is entirely in lower case, with no punctuation. Decoder.java should try all keys from 0 to 25 (including 0 to see the original), and print out each message to the screen. The user can then look at the 26 messages to see which one turns out to be in English. Tips
Have fun, and good luck! |
|
Moodle Docs for this page