I am using the modulo operator on vigenere but not sure where I am going wrong. following is part of my code,
//get plain text
string p = GetString();
//encipher
string k = argv[1];
for (int i = 0, n = strlen(p); i < n; i++)
{
if(isalpha(p[i]))
{
int j = 0;
int m = strlen(k);
while(j < m)
{
k[j] = ((int) tolower(k[j] - 'a'));
if(isupper(p[i]))
{
int aiu = (int) p[i] - 'A'; //alphabetical index(ai)
int c = ((aiu + k[j]) % 26); //caesar cipher
printf("%c", c + 'A'); //back to ascii
}
if(islower(p[i]))
{
int ail = (int) p[i] - 'a';
int c = ((ail + k[j]) % 26);
printf("%c", c + 'a');
}
i++;
j = j % m;
j++;
}
}
else
{
printf("%c", p[i]);
}
}
printf("\n");
1). it fails to print special character 2). prints correct cyphertext(ct) for plaintext(pt) equal or smaller than ct. 3). considers numbers as non alpha and prints them as is, only if input(ed) at the beginning of the pt i.e. key = ab pt = 12cd ct = 12ce but pt = cd12 gives ct = ce2 4). few others including makes me feel disappointed(read frustrated) in my abilities.