【发布时间】:2016-11-10 16:12:30
【问题描述】:
我有一个已经使用移位加密的文本文件,但我需要再次加密加密文本,但这次使用 vigenere 密码。然后,我需要解密该加密文本(首先是 vigenere,然后是移位),但所有大写和小写字母以及空格、引号、逗号和句号都需要保持不变。我已经完成了shift加解密,剩下的就是vigenere了。下面显示的是我的加密 Vigenere 课程,我还没有编写解密,因为我被困在加密步骤中。 谢谢。
public static String vigenereEncryption(String str,String keyword)
{
char [] c_arr = null;
int g =0;
int keyLength = keyword.length();
String encrypted = "";
String update ="";
String []list = null;
for(int k = 0; k<keyword.length();k++){
char key = keyword.charAt(k);
c_arr = keyword.toCharArray();
update = update + key;
}
for(int i=0;i<str.length();i++)
{
//stores ascii value of character in the string at index 'i'
int c=str.charAt(i);
//encryption logic for uppercase letters
if(Character.isUpperCase(c))
{
for(int k = 0; k<keyword.length();k++){
g = c_arr[k] ;
}
c=(c+g)%26;
//if c value exceeds the ascii value of 'Z' reduce it by subtracting 26(no.of alphabets) to keep in boundaries of ascii values of 'A' and 'Z'
if(c>'Z')
c=c-26;
}
//encryption logic for lowercase letters
else if(Character.isLowerCase(c))
{
c=(c+g)%26;
//if c value exceeds the ascii value of 'z' reduce it by subtracting 26(no.of alphabets) to keep in boundaries of ascii values of 'a' and 'z'
if(c>'z')
c=c-26;
}
//concatinate the encrypted characters/strings
encrypted=encrypted+(char) c;
}
return encrypted;}}//end of public class`
【问题讨论】:
标签: java encryption cryptography vigenere