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?