0

Currently doing Vigenere, and I made it to the final steps. My code for iterating over the key and the shift function are as follows:

for (int j = 0; j < strlen(argv[1]); j++)
{
    counter = counter + 1;
    if (isalpha(plainText[i]) == false)
    {
        j = j - 1;
    }
    if (j >= counter)
    {
        j = 0;
    }
    key = shift(argv[1][i]);
}

...

int shift(char c)
{
    if (islower (c))
    {
        c = c - 97;
    }
    else if (isupper (c))
    {
        c = c - 65;
    }
    return c;
}

Using printf to see the value of shift, if the keyword given is smaller than the plaintext, the value of shift doesn't really work properly.

ex. running vigenere with keyword 'bc' and plaintext 'hello', the value of shift goes 1, 2, 0, 1, 2. Although, when using a keyword with equal length to the plaintext ('bcdef' and 'hello') the value of shift is normal; 1, 2, 3, 4, 5.

Any idea on whats wrong and how to fix this bug?

Thanks, everyone.

1

Shouldn't

key = shift(argv[1][i]);

be using j instead of i? j is your increment value for the key.

| improve this answer | |

You must log in to answer this question.

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