У меня проблема с Vigenere и мне нужна помощь.CS50 Vigenere - Strange pattern
/*
This program is a Vigenere Cipher.
I am Daniel of Asguard.
*/
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string argv[])
{
string cipher; //this is a placeholder for the ciphered message.
char * key = argv[1];
int i = 0;
if (argc != 2) //this is meant to trigger if you don't enter the right call. So
{
printf("Please enter the cipher key when you call the program, such as './CaesarCipher 7'.\n"); //
return 1;
}
if (!isalpha(key[i])) //this is meant to trigger if you don't enter the right call. So
{
printf("Please only enter a word, no numerical numbers please."); //
return 1;
}
do
{
//printf("Please enter the message you would like to have converted, please. \n");
cipher = GetString();
}
while (cipher == NULL);
for (int i = 0, k = 0, n = strlen(cipher); i < n; i++, k++) //this is so the code knows to change only the characters in the sting cipher.
{
if (k >= strlen(key))
{
k = 0;
}
{
if (isupper(cipher[i]))
{
//cipher[i] = 'A' + (((cipher[i] - 'A') + (key[k]) - 'A') % 26);
cipher[i] = ((key[k] - 65) + (cipher[i] - 65)) % 26;
printf("%s\n", cipher);
}
else (islower(cipher[i]));
{
//cipher[i] = 'a' + (((cipher[i] - 'a') + (key[i]) - 'a') % 26);
cipher[i] = ((key[k] - 97) + (cipher[i] - 97)) % 26;
printf("%s\n", cipher);
}
}
}
printf("%s\n", cipher);
return 0;
}
Когда я делаю это мои результаты будут получены странные символы: ⎽c▒⎺e┼├⎼▒┤└e⎼ @ ☃de5▮: ·/┬⎺⎼┐⎽⎻▒ce/⎻⎽e├ 2 $ └▒┐e ┴☃ ± e┼e⎼e для всех букв в моем терминале после завершения.
Мои результаты в конечном итоге выглядит, как это для БАЗ:
- Anything примечания
- nything примечания
- ружения примечания
- ружения примечания
- вещь Примечание
- примечание
- примечание
- нг Примечания
- примечания
- примечания
- F Примечание
- F Примечание
- Примечание
- ОТ
- ОТЕ
- ОТЕ
- ├e
- е