我對Vigenere有點問題,並希望得到一些幫助。CS50 Vigenere - 奇怪的圖案
/*
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於完成後,我的終端所有的信件。
我的結果落得這樣看的巴茲:注意
- 任何
- nything注
- ything注
- ything注
- 事情注
- 備註
- 備註
- NG注注
- 注
- F注意
- F注意
- 注
- OTE
- OTE
- OTE
- ├e
- 電子商務