So in my program I am supposed to have a driver class and utility class. I have to write a program that uses the same type of Cryptography as Caesar did. For example a = f, b = g, c = h, and so on. In my driver class is where I am supposed to have the decoding and encoding process. The file has to be encrypted/decrypted using command line arguments. For example,
java CaesarLab encode "keyword" message.txt
In the utility class is where the shifting of letters should be. This is where I know to put this code:
public static final int NUM_LETTERS = 26;
// shifting up for the encoding process
public static char shiftUpByK(char c, int k) {
if ('a' <= c && c <= 'z')
return (char) ('a' + (c - 'a' + k) % NUM_LETTERS);
if ('A' <= c && c <= 'Z')
return (char) ('A' + (c-'A' + k) % NUM_LETTERS);
return c; // don't encrypt if not an alphabetic character
}
// shifting down for the decoding process
public static char shiftDownByK(char c, int k) {
return shiftUpByK(c, NUM_LETTERS - k);
}
It should also read from a FileInputStream, and handle exception/errors by catching all I/O exceptions.
There seems to be a lot of components to this program and I am having trouble putting it all together. If i could get some help in sorting all of this out, it would be greatly appreciated.