I've got my code to cycle through the plaintext index p and the key index. However I keep getting an error when I am printing and can't figure it out. When I use the test spec using bacon as the key and "Meet me at" for string p. instead of getting "Negh zf av" I get "Negh z gb" where it is deleting a character. It is must not be cycling through the key index properly as it is moving 2 places however I cant understand why a char is being removed.
Appreciate any kind help
{
string key = argv[1];
string p = GetString();
for (int i = 0, j = 0, n = strlen(p); i < n; i++)
{
if (isupper(p[i]))
{
if (isupper(key[j]))
{
int k = (key[j % strlen(key)] - 65) % 26;
char ciph = ((p[i]- 65 + k) % 26) + 65;
printf("%c", ciph);
}
if (islower(key[j]))
{
int k = (key[j % strlen(key)] - 97) % 26;
char ciph = ((p[i]- 65 + k) % 26) + 65;
printf("%c", ciph);
}
}
if (islower(p[i]))
{
if (isupper(key[j]))
{
int m = (key[j % strlen(key)] - 65) % 26;
char ciph = ((p[i]- 97 + m) % 26) + 97;
printf("%c", ciph);
}
if (islower(key[j]))
{
int m = (key[j % strlen(key)] - 97) % 26;
char ciph = ((p[i]- 97 + m) % 26) + 97;
printf("%c", ciph);
}
}
if (isalpha(p[i]))
j++;
else
{
printf("%c", p[i]);
}
}