我正在尝试创建一个 vigenere 密码,但我遇到了分段错误。我相当新,如果有人可以提供帮助,我将不胜感激。先感谢您。
// Mukul Patel February 26, 2014
int my_key(string key)
{
int key_length = 0;
while (key[key_length] != '\0')
key_length++;
return key_length;
}
int main(int argc, string argv[])
{
if (argc != 2){
printf("Please only enter two arguments which are non-numerical\n");
return 1;
}
string key = argv[1];
string plaintext = GetString();
for (int i = 0, length = strlen(plaintext); i < length; i++){
for (int j = 0, n = my_key(argv[i]); j < n; j++){
if(isupper(plaintext[i]))
plaintext[i] = ((((plaintext[i] - 'A') + (key[j % strlen(key)] - 'A')) % ALPHABET) + 'A');
else if(islower(plaintext[i]))
plaintext[i] = ((((plaintext[i] - 'a') + (key[j % strlen(key)] - 'a')) % ALPHABET) + 'a');
else
plaintext[i] = plaintext[i];
printf("%c", plaintext[i]);
}
}
printf("\n");
return 0;
}