So I've been working on pset2 problems with everything going good, until I came across Vigenere cipher. In short it gives me wrong output all the time, any help would be very appreciated!
Here is my code :
char cipher(string text, string key)
{
for (int i = 0, n = strlen(text); i < n; i++)
{
if isalpha(text[i])
{
for (int y = 0,l = strlen(key); y < l; y++)
{
if (islower(text[i]))
{
printf("%c", ((((char) text[i] +(char) key[i % l]) - 97) % 26) + 97);
}
if (isupper(text[i]))
{
printf("%c", ((((char) text[i] +(char) key[i % l]) - 65) % 26) + 65);
}
else
{
printf("%c", text[i]);
}
}
}
}
printf("\n");
return 0;
}
I'm still new to coding so bear with me ^^
Thanks.