Vigenere 对消息的加密不正确,例如,如果密钥是“hello”而消息是 hello,则加密文本现在是“eipsv”,而应该是“hello”。
我真的很感激有关修复此错误的任何提示。
string message = GetString();
int m = strlen(message);
int i = 0;
if(isalpha(message[i]))
{
for(int j = 0; j < n; i++)
{
key[j] = tolower(key[j]) - 97;
j++;
for (i = 0; i < m; i++)
{
char c = message[i];
if (islower(c))
{
c = (((c - 'a' + key[j%n])%26) +'a');
j++;
printf("%c", c);
}
if (isupper (c))
{
c = (((c - 'A' + key[j%n])%26) +'A');
j++;
printf("%c", c);
}
else if (!isupper(c) && !islower(c))
{
printf("%c", c);
j++;
}
}
}
}
printf("\n");
}