這就是我目前所擁有的。它應該找到以明文形式輸入的字母,將它與字母表中的字母匹配(區分大小寫),然後根據輸入的奇數鍵或偶數鍵進行切換,這將在稍後執行。但目前,這是我得到的輸出。在java中編寫一個多字母轉換密碼
what would you like to encrypt?
abcdefg
enter oddkey
1
Now enter the evenkey
1
B
BB
BBB
BBBB
BBBBB
BBBBBB
BBBBBBB
這是代碼
String PlainText = "", cipherText = "";
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- ";
System.out.println("what would you like to encrypt?");
PlainText = input.nextLine();
System.out.println("enter oddkey");
oddkey = input.nextInt();
System.out.println("Now enter the evenkey");
evenkey = input.nextInt();
for (int i = 0; i < PlainText.length(); i ++)
{for (int m = 1; m < alpha.length(); m ++)
{if (alpha.charAt(m-1) == PlainText.charAt(i));
cipherText = cipherText + alpha.charAt(m - 1 + evenkey);
System.out.println(cipherText);
}}
所以我在做什麼錯,它只是重複BBBBBBB,而不是正確的換擋字母的開始?有什麼建議?
而且你的問題是??? – pczeus
對不起,把它添加到最後。 – Wookiegonewild