因此,对于我的一生,我无法弄清楚为什么没有输入用于加密的 for 循环!我已经放置了一些打印语句来确认它没有进入理论上它应该在 3 次内打印 im,而是进入第一个条件但随后没有进入第一个 for 循环(由 i 控制的那个)
//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