0

I came up with these lines of code to get from a character in the plaintext to a new character in the ciphertext. I keep getting an ouput of 0 everytime I run it, no matter which key I choose or which input I give. I think something must be going wrong with the formula or the ACII values but I can't see what it is exactly. Many thanks if you wanna have a look at it!

//Check if lower or upper and prints character of ciphertext

        if islower(plaintext[i])
        {
            aiplain = plaintext[i] - 97;
            aicipher = (aiplain + key) % 26;
            ciphertext = aicipher + 97;
            printf ("%c", ciphertext);
        }


        else if (isupper(plaintext[i]))
        {
            aiplain = plaintext[i] - 65;
            aicipher = (aiplain + key) % 26;
            ciphertext = aicipher + 65;
            printf ("%c", ciphertext);
        }
0

If the code is outputting 0s, then the problem likely lies elsewhere in your code. You should take a close look at the code leading up to this block of code. Also, run the code in debug50 and step through it one line at a time and watch where the 0 is being generated.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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