# pset2 Vigenere: Problems Applying Key & Case

for (int i = 0, n = strlen(p); i < n; i++)
{
if (isalpha(p[i]))
{
if (isupper(p[i]))
{
char stringshifttext = ((((p[i] - 'A') + (k[i % strlen(k)] - 'A')) % 26) + 'A');
printf("%c", stringshifttext);
}

else if (islower(p[i]))
{
char stringshifttext = ((((p[i] - 'a') + (k[i % strlen(k)] - 'a')) % 26) + 'a');
printf("%c", stringshifttext);
}
}


I'm having trouble getting my key to apply universally.
K = BBBBB
P = ZzZzz
Result = A[A[[

K = bbbbb
P = ZzZzz
Result = GaGaa

When the key is uppercase and the inputed text is uppercase, it works.
When the key is lowercase and the inputed text is lowercase, it works.

If the key and the inputed text do not match case, it doesn't work.

Do I need to change the key somehow? Or change how it's being applied?

Quite simply, yes. You have implemented two of four possible combinations - the two where they are the same case. Now, you need to implement the cases where they are different case. Of course, if you were to figure out a way to handle the key where the case doesn't matter, then it would make things simpler. I suspect that you'll find tolower() or toupper() of use.