일부 암호화를 구현하고 싶습니다. 따라서 Vigenere 암호에 대한 코드가 필요합니다. 누구든지 Java 용 소스 코드를 어디에서 찾을 수 있는지 알고 있습니까?어디에서 Vigenere 암호 용 Java 소스 코드를 찾을 수 있습니까? 내 앱에서
답변
여기에 Vigenere Cipher Code 구현 Sample Java Code to Encrypt and Decrypt using Vigenere Cipher에 대한 링크가 있으며, Vigenere Cipher를 암호화로 사용하지 않는 것이 좋습니다.
나는 jBCrypt을 권장합니다.
게시 한 링크가 이제 종료되었습니다. – GeoGriffin
@GeoGriffin 지적 해 주셔서 감사합니다. 다른 예제 링크를 업데이트했습니다. –
다시 죽었습니다. – Omore
이것은 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;
}
}
AFAIK 아주 단순한 암호입니다. 왜 직접 구현하지 않습니까? Java 암호화 라이브러리에 구현이 있는지 실제로 확인할 수 있습니다. 실제 응용 프로그램에서 Vigenere 암호를 사용하지 않는 것이 좋습니다. – Egor
이 링크에서 답변을 찾을 수 있습니다. http://stackoverflow.com/questions/10280637/vigenere-cipher-in-java-for-all-utf-8-characters –