:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword \ expected output, but not "xoqmd, szz gflkp!\n" :( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword \ expected output, but not "CaQGoh\n"
My code meets every other check except these 2. I realize they may be(and probably are) two different problems. My outputs are just so close to the correct ones that its hard for me to find the error. Like why is 'say' the only word that is wrong in the sentence? Or why is CaQGon made into CaQGoh? Why the h?
{
string key = argv[1];
if ((argc != 2))
{
printf("Please enter a correct key!\n");
return 1;
}
for (int i = 0, n = strlen(key); i<n; i++)
{
if (!isalpha(key[i]))
{
printf("Please enter a correct key!\n");
return 1;
}
}
string p = GetString();
for (int i = 0, j = 0, n = strlen(p); i < n ; i++)
{
if (isupper (p[i]))
{
printf("%c", ((((p[i] - 'A') + (key[i % strlen(key)] - 'A')) % 26) + 'A'));
j++;
}
else if (islower (p[i]))
{
printf("%c", ((((p[i] - 'a') + (key[i % strlen(key)] - 'a')) % 26) + 'a'));
j++;
}
else
{
printf("%c", p[i]);
}
}
printf("\n");
return (0);
Thank you in advance!