-2

したがって、私の人生では、暗号化の for ループが入力されていない理由がわかりません! 私はいくつかの print ステートメントを配置して、理論的にはim を 3 回以内に出力する必要があることを確認しました。

    //method for Ceaser encryption takes in a string in plain text or encrypted form, the key, and mode option
public static String ceaser(String a, int x, int T ){

    System.out.println(a);
    System.out.println(x);
    System.out.println(T);
    String full = "abcdefghijklmnopqrstuvwxyz";
    String output ="";
    //used for type matching for concat method
    String convertChar="";
    char[] alpha = full.toCharArray();

    //used to find the inital value (index of the plain text letter in the alphabet 
    int position = 0;


    //selecting encryption
    if(T==1){
        System.out.println("im inside");
        for (int i=0; i>a.length(); i++){
            System.out.println("im inside");
            for (int l=0; l>full.length(); l++){
                System.out.println("im inside");
                System.out.println(a.charAt(i));

                if (a.charAt(i) == full.charAt(l))
                    System.out.println(full.charAt(l));
                    position = l;
                    System.out.println(position);

            }
                //Handling the circular property of the shift
                if ((position + x) > 25){
                    System.out.println(convertChar);
                    convertChar = Character.toString(full.charAt((25-position)-x));
                    System.out.println(convertChar);
                    output.concat(convertChar);
                }
            else{
                System.out.println(convertChar);
                convertChar = Character.toString(full.charAt(position + x));
                System.out.println(convertChar);
                output.concat(convertChar);
            }
        }
    }
    // Selecting decryption
    else {
        for (int u=0; u>a.length(); u++){

            for (int b=0; b>full.length(); b++){
                if (a.charAt(u) == full.charAt(b))
                    position = b;

                //handling circular property
                if((position - x) < 0){
                    convertChar = Character.toString(full.charAt(25-(x-position)));
                    output.concat(convertChar);
                }
                //applying inverse shift
                else{

                    //try printng out convert char for debug
                    convertChar = Character.toString(full.charAt(position - x));
                    output.concat(convertChar);
                }

            }
        }
    }
    //displaying the output
    System.out.println(output);
    System.out.println("death of ceaser");
    return output;
}

プログラムの現在の出力は次のとおりです。

    Please select the type of encryption you would like performed enter 1 for Ceaser, 2 for vigenere, or 3 for matrix transposition
1
Please enter 1 for encryption or 2 for decryption
1
Please input the string you want encrypted or decrypted: 
yuck
Enter the amount to shift by, aka the Key: 
2
yuck
2
1
im inside

death of ceaser
4

3 に答える 3

5

ループ条件の終了を示すには、未満 を使用します。<交換:

for (int i=0; i>a.length(); i++){

for (int i=0; i < a.length(); i++){

同じことがここにも当てはまります:

for (int l=0; l>full.length(); l++){

への変更

for (int l=0; l < full.length(); l++){
于 2013-02-24T15:10:15.807 に答える
2
 for (int i=0; i>a.length(); i++){
            System.out.println("im inside");
            for (int l=0; l>full.length(); l++){

間違った演算子と比較していると思いますが、i < a.length()andではないl < full.length()でしょうか?

于 2013-02-24T15:10:36.050 に答える
1

これはあなたが持っているからです

i>a.length()

iゼロから始まるため、文字列がどれほど短くても、文字列の長さを超えることはできません。

条件を次のように変更する必要があります。i < a.length()

于 2013-02-24T15:10:49.703 に答える