チッパーラボで助けが必要です。私の指示は次のとおりです。
コマンドライン引数として任意の数の文字列を受け入れ、Atbash 暗号で暗号化された文字列を表示するプログラムを作成します。プログラムは可能な限りモジュール化して、優れたオブジェクト指向プログラミング手法を使用する必要があります。プログラムは、javadoc コメントを使用して完全に文書化する必要があります。
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
AがZを返し、BがYを返すように、文字列をエンコードする必要があります。Eclipse で暗号化ラボを実行しましたが、実行されていません。何が間違っているのかわかりません。
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);
}
}