2015-10-30 4 views
-2

Я пишу программу Vigenere cypher в C для CS50 и работаю почти отлично. Ошибка в том, что иногда, когда шифрование обертывает выходной файл? символ в белом круге.Ошибка программы Vigenere cypher для cs50

Ниже мой код;

#include <cs50.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <ctype.h> 

int main(int argc, string argv[]) 
{ 
char a; 
char letter; 
char cryptletter; 
char passletter; 
string message; 
int messcount = 0; 

if(argc != 2) 
{ 
    printf("Command line must contain one passphrase\n"); 
    return 1; 
} 

for(int i=0; i < strlen(argv[1]); i++) 
{ 
    a = argv[1][i]; 

    if(isalpha(a) == 0) 
    { 
     printf("Encryption keyphrase must only contain alphabetic characters\n"); 
     return 1; 
    } 
} 


message = GetString(); 


for (int j = 0; j < strlen(message); j++) 
{ 
    letter = message[j]; 

    if(passletter < 91 && passletter > 64) 
    { 
     passletter = passletter + 32; 
    } 

    if(isupper(letter) != 0) //if uppercase 65-90 
    { 
     passletter = argv[1][messcount]; 
     cryptletter = passletter + letter - 97; 

     if(cryptletter > 90) 
     { 
      cryptletter = cryptletter - 25; 
     } 

     printf("%c", cryptletter); 
     messcount++; 
    } 

    if(islower(letter) != 0) //if lowercase 97-122 
    { 
     passletter = argv[1][messcount]; 
     cryptletter = passletter + letter - 97; 

     if(cryptletter > 122) 
     { 
      cryptletter = cryptletter - 25; 
     } 

     printf("%c", cryptletter); 
     messcount++; 
    } 


    if(messcount > strlen(argv[1])-1) 
    { 
     messcount = 0; 
    } 

    if (isalpha(letter) == 0) 
    { 
     printf("%c", letter); 
    } 
} 

printf("\n"); 
} 

Любая помощь будет принята с благодарностью, если у вас возникнет аналогичная проблема с caesar cypher. Благодаря

ответ

1

Здесь:

if(passletter < 91 && passletter > 64) 

passletter не инициализирован