I Don't know how to make code work if key is lowercase and text uppercase and vice-versa. Before I considered case sensitivity my code would work except for a few letters. Now it wont output full ciphertext. Can anybody tell me what I am not seeing?
for(int i = 0, n = strlen(text); i < n; i++)
if(isalpha(text[i]))
{
if(isupper(text[i]))
{
//char cipher = (text[i] - 'A' + key[j % k_len] - 'A') % 26;
if(isupper(key[j]))
{
char cipher = (text[i] - 'A' + key[j % k_len] - 'A') % 26;
printf("%c", cipher + 'A');
j++;
}
if(islower(key[j]))
{
char cipher = (text[i] - 'A' + key[j % k_len] -'a') % 26;
printf("%c", cipher + 'a');
j++;
}
}
if(islower(text[i]))
{
//char cipher = (text[i] - 'a' + key[j % k_len] - 'a') % 26;
if(isupper(key[j]))
{
char cipher = (text[i] - 'a' + key[j % k_len] - 'A') % 26;
printf("%c", cipher + 'a');
j++;
}
if(islower(key[j]))
{
char cipher = (text[i] - 'a' + key[j % k_len] -'a') % 26;
printf("%c", cipher + 'a');
j++;
}
}
}
else
{
printf("%c", text[i]);
}
printf("\n");
}