小さな暗号化プログラムを作成しようとしています。オプションの1つは「キーで暗号化する」です。私が理解できないことは、文字列に基づいてメッセージを暗号化する方法を作成する方法です。暗号化キーを使用してメッセージを暗号化する方法
public static void encodeWithKey(){
System.out.println("What is the encryption key?");
String encryptKey = scan.nextLine();
System.out.println("What is the message to encrypt?");
String messageWithKey = scan.nextLine();
StringBuilder encryptWithKeyBuilder = new StringBuilder();
for (char c : messageWithKey.toCharArray()) {
// Add 1 to each character and append it
encryptWithKeyBuilder.append((char) (c - 1));
}
// Now the builder contains the String with the shifted values
System.out.println("Your encoded message is: ");
System.out.print(encryptWithKeyBuilder);
}
暗号化キーの最初の2文字を見つけて整数に変換し、それらを一緒に追加したいとします。次に、(新しい番号に「1」の交換、forループインチ)のメッセージを暗号化するためにそれを使用、次のように
あなたはこれで困っていますか? –
@nazar_art私はちょうどそれを行う方法がわかりません。私はJavaに比較的新しい(1年足らず)と、ほとんどが独学です。 –