在执行期间,调用该方法,整数i显示0在屏幕上.但是,for循环内部没有输出,表明for循环没有执行.我还用断点测试了它,并获得了相同的结果.任何帮助表示赞赏.
i
private void decrypt_btnActionPerformed(java.awt.event.ActionEvent evt) {
int ciphertext_length = Ciphertext().length();
String decrypted_char = "";
int i = 0;
System.out.println("increment" + i);
try {
for (i = 0; i == ciphertext_length; i++) {
System.out.println("test" + i);
String cipher_current_char = getLetterAtIndex(Ciphertext(), i);
int pos_char_in_alphabet = getIndexAtLetter(Alphabet(), cipher_current_char);
decrypted_char = decrypted_char +
getLetterAtIndex(Alphabet(), pos_char_in_alphabet - 5);
status_label.setText(100 / i + "%");
}
} catch (Exception e) {
e.getMessage();
}
plain_ta.setText(decrypted_char);
}
Run Code Online (Sandbox Code Playgroud) 在以下代码中,永远不会执行for循环.我试图用断点和手表解决问题.返回密文的正确长度,但for循环直到没有增加int i >= ciphertext.length().事实上,似乎没有任何东西执行过'Debug'消息.
private void decrypt_btnActionPerformed(java.awt.event.ActionEvent evt) {
String alphabet= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
String ciphertext="fRcXFBxXTRJ";
status_label.setText( "Decryption has begun" );
JOptionPane.showMessageDialog(null,"ciphertext-length: " + ciphertext.length() + "\n" + ciphertext,"Debug", JOptionPane.INFORMATION_MESSAGE);
for (int i = 0; i>=ciphertext.length(); i--){
System.out.println("inc:" + i);
String cipher_current_char = getLetterAtIndex(ciphertext, i);
int pos_char_in_alphabet = getIndexAtLetter(alphabet, cipher_current_char);
if(pos_char_in_alphabet-2<0){
plain_ta.setText(getLetterAtIndex(alphabet, (alphabet.length()+(pos_char_in_alphabet -2)+1 ) ));
status_label.setText( 100/i + "%");
}else{
cipher_current_char = getLetterAtIndex(ciphertext, i);
pos_char_in_alphabet = getIndexAtLetter(alphabet, cipher_current_char);
plain_ta.setText(getLetterAtIndex(alphabet, (pos_char_in_alphabet-2)));
status_label.setText( 100/i + "%");
}
}
}
Run Code Online (Sandbox Code Playgroud)