0

The logical error is occurring when i try to shift each character of the plaintext by 1

 string plaintext= get_string("plaintext: ");
    //aplplying key
    for(int j=0,m=strlen(plaintext);j<m;j++)
    {
        if(isalpha(plaintext[j]))
        {
            char c= plaintext[j];
         printf("ciphertext: %c",c+1);
        }
        else
        printf("%c",plaintext[j]);
    }
    printf("\n");

The flawed output:

./caesar 2
2
plaintext: hi
ciphertext: iciphertext: j

0

Your error is in the line printf("ciphertext: %c", c+1);. Do you really want to print "ciphertext:" for each iteration through your loop or just the character?

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .