私のアプリでは、暗号化を実装したいと考えていました。したがって、Vigenere 暗号のコードが必要です。Javaのソースコードがどこにあるか知っている人はいますか?
26442 次
3 に答える
12
これは Vigenere 暗号クラスです。暗号化および復号化関数を呼び出すだけで使用できます。コードはRosetta Codeからのものです。
public class VigenereCipher {
public static void main(String[] args) {
String key = "VIGENERECIPHER";
String ori = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";
String enc = encrypt(ori, key);
System.out.println(enc);
System.out.println(decrypt(enc, key));
}
static String encrypt(String text, final String key) {
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') continue;
res += (char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
j = ++j % key.length();
}
return res;
}
static String decrypt(String text, final String key) {
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') continue;
res += (char)((c - key.charAt(j) + 26) % 26 + 'A');
j = ++j % key.length();
}
return res;
}
}
于 2012-07-05T15:23:31.047 に答える
2
これは Vigenere Cipher Code implementation Sample Java Code to Encrypt and Decrypt using Vigenere Cipherへのリンクですが、Vigenere Cipher を暗号化として使用することはお勧めできません。
jBCryptをお勧めします。
于 2012-07-05T15:18:49.607 に答える
1
この投稿が役に立ちます。解読用のコード全体が提供されています。これを使用して暗号化コードを記述できます
于 2014-02-21T16:57:04.420 に答える