I need help with my chiper lab. My instructions are:
Write a program that accepts any number of strings as command-line
arguments and displays those strings encrypted with the Atbash cipher.
You program should be as modular as possible and use good object
oriented programming techniques. Your program must be thoroughly
documented using javadoc comments.
I have String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; that should encode strings so that A would return Z and B would return Y and so on. I did my cipher lab in Eclipse and it’s not running. I’m not sure what I’m doing wrong.
public class CaesarCipher {
public static void main(String[] args) {
CaesarCipher cc = new CaesarCipher();
}
public static final int ALPHASIZE = 26;
public static final char [] alpha = {'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'};
protected char[] encrypt = new char[ALPHASIZE];
protected char[] decrypt = new char[ALPHASIZE];
public CaesarCipher() {
for (int i=0; i<ALPHASIZE; i++)
encrypt[i] = alpha[(i + 3) % ALPHASIZE];
for (int i=0; i<ALPHASIZE; i++)
decrypt[encrypt[i] - 'A'] = alpha[i];
}
/** Encryption Method */
public String encrypt(String secret) {
char[] mess = secret.toCharArray();
for (int i=0; i<mess.length; i++)
if (Character.isUpperCase(mess[i]))
mess[i] = encrypt[mess[i] - 'A'];
return new String(mess);
}
/** Decryption Method */
public String decrypt(String secret) {
char[] mess = secret.toCharArray();
for (int i=0; i<mess.length; i++)
if (Character.isUpperCase(mess[i]))
mess[i] = decrypt[mess[i] - 'A'];
return new String(mess);
}
}
Try this: