我有 Vigenère cipher java 代码,它运行良好,但我想用斐波那契公式修改此代码,所以加密结果就像一次性填充方法.. 这是代码:
public class Coba {
public static void main(String[] args) {
String key = "abcd";
String ori = "satusatu";
String enc = enkripsibaru(ori, key);
System.out.println(enc);
System.out.println(key);
System.out.println(ori);
System.out.println(dekripsibaru(enc, key));
}
static String enkripsibaru (String plaintext, String key)
{
String s = "";
int lengthPlainText = plaintext.length();
int lengthKey = key.length();
int j = 0;
for (int i = 0; i < lengthPlainText; i++)
{
if (j >= lengthKey)
{
key = plaintext;
lengthKey = lengthPlainText;
j = 0;
}
s += (char) (((int) plaintext.charAt(i) + key.charAt(j))%26);
j++;
}
return s;
}
public static String dekripsibaru(String cipher, String kunci)
{
String s = "";
int lengthCipherText = cipher.length();
int lengthKey = kunci.length();
int j = 0;
int temp1;
int a = 0;
for (int i = 0; i<lengthCipherText; i++)
{
if (j >= lengthKey)
{
temp1 = (int) cipher.charAt(i) - (int) s.charAt(a);
if (temp1 < 0) {
temp1 += 26;
}
s += (char) (temp1 % 26);
a++;
}
else
{
temp1 = (int) cipher.charAt(i) - (int) kunci.charAt(j);
if (temp1 < 0)
{
temp1 += 26;
}
s += (char) (temp1 % 26);
}
j++;
}
return s;
}
}
我应该如何处理这段代码以与斐波那契相结合?谢谢