PDA

Click to See Complete Forum and Search --> : Ceaser cipher program help.


cisc 190
Mar 17th, 2011, 07:53 PM
i really need help to create a program, i jus need it so that i can understand it more than i do now

These are the requirements:

Develop a program that uses dialog boxes to ask the user for the name of an input file, an output file, and if the input file needs to be encoded or decoded. Depending on the user’s input, the input file should be encoded or decoded using a Caesar Cipher (http://en.wikipedia.org/wiki/Caesar_cipher) and the output written to the output file. Basically, a Caesar Cipher works by replacing the current character with the character three positions down in the alphabet (e.g. A becomes D). This replacement is also known as the shift.
For example:
Encoding: “hello” becomes “khoor”
Decoding: “khoor” becomes “hello”

Details
Your final program should have two public classes. The first class should be called “EncryptXX” where the XX represents your initials. This class should only contain the main method, which will be used to interact with the user and reading/writing to files. The second class should be called “CipherXX” where the XX represents your initials. This class should contain, at a minimum, two methods: “encode” and “decode”. The “encode” method should be used in transforming the plaintext into ciphertext and the “decode” method should be used in transforming the ciphertext back to plaintext. When encoding or decoding, do not worry about non-letters (i.e. numbers and special characters), just encode/decode them as is. For example, “1998!$%” would encode to “1998!$%”. However, uppercase letters should encode and decode to corresponding uppercase letters; the same goes for lowercase. Finally, your solution should not be a large switch statement and the shift should be easily changed.

The project has multiple steps. You are strongly encouraged to solve each step completely - including thorough testing - before you move on to the next step. Also, remember that your program’s source code must comply with the Java Style Guide in order to maximize the grade you receive on this project. Compile your program often so you do not end up with a snake’s nest of errors at your first compile, and occasionally save a backup copy of your program’s source code in case your dog eats your X drive.
Useful Information

This program should test your knowledge of developing a fairly simple Java program that utilizes classes and various types of if statements, variable types, methods, and loops.

Just for comparison, my solution to this assignment was 45 lines of code for the “EncryptXX” class and 55 lines of code for the “CipherXX” class (that includes blank lines between logical sections of the code but does not include comments).

For this project, make sure to look at all the tools that have been presented to you up to this point (e.g. if statements, loops, relational operators, methods, classes, etc.).

Useful code
You will need to use the FileReader class to read input from your input file. You will need to create an instance of the FileReader class so look at the Constructors for the FileReader class. Two methods from the FileReader class that you will probably need for this assignment are read() and ready(). The read method returns the next character in a file in the form of an int (think about what you need to do to use it). The ready method returns a boolean indicating that the file has at least one more character to be read.
You will need to import this statement in your code to use the FileReader class.
java.io.FileReader;

You will need to modify the method header of your main method to
public static void main(String[] args) throws IOException
and import this statement in your EncryptXX class
import java.io.IOException;

Demon-Mask
Jun 1st, 2011, 01:00 PM
You will need to make an array with all of the letters in the alphabet, read the file, find the positions of the letters in your array, then shift the values of the positions by three, and print the letters occupying the new positions.
That is what I'd try first.

OT²O
Jun 1st, 2011, 09:11 PM
You will need to make an array with all of the letters in the alphabet, read the file, find the positions of the letters in your array, then shift the values of the positions by three, and print the letters occupying the new positions.
That is what I'd try first.

My thoughts exactly.

Demon-Mask
Jun 2nd, 2011, 12:22 PM
Well, there aren't many different ways you can solve this sort of problem in Java.