我正在查看http://rosettacode.org/wiki/Vigen%C3%A8re_cipher#Java上提供的Vigene Ciphere源代码。我试着自己测试了这个程序,并没有输出我期望基于vigene的值。例如'dog'这个词,'bob'是我希望这个被加密为'ech'的关键字,但是'qot'代替。Vigenere密码输出
public static void main(String[] args) {
String key = "bob";
String ori = "dog";
String enc = encrypt(ori, key);
System.out.println(enc);
}
static String encrypt(String text, final String key) {
String res = "";
text = text.toLowerCase();
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;
}
但是输出是不同的。这是因为我对密码的理解是不正确的,或者这对于众所周知的vigenere密码采取了不同的方法。
“但是,输出是不同的”它是什么呢? –
@AndyTurner QOT – Rishav
@RishavKundu假设这不仅仅是我没听说过的缩写词,最好在问题中加入它 - 补充。 –