I'm having trouble figuring out where/how to apply the modulo operator to the key. It seems to me that this code should work, but the output is incorrect at any letter beyond the string length of the key.
Please note that I have excluded all parts of the code that I believe to be irrelevant to the question at hand.
string encrypt = GetString();
string key = argv[1];
for (int i = 0, j = 0, k = strlen(encrypt); i < k; i++)
{
j = j % k;
printf ("%c", (((encrypt[i] - 97) + (key[j] - 97)) % 26) + 97);
j++;
}
}