I can't figure out how to wrap the k[i] in the formula c[i] = (p[i] + k[i]) % 26
I know the if and else code's are different, that's to illustrate the main implications I've tried. also the printf("%d", v); was intentional and used to try and find out where it was going wrong.
a key of aaa successful encrypts a message of similar length but if the message is longer than the key it will print the wrong encryption
any help would be much appreciated!
string d = argv[1]
printf("Encrypted message: ");
for (int i = 0, n = strlen(om); i < n; i++) /* checks if i th character of om is in the alphabet, if yes then checks if upper or lower and converts to alphabet value, adds key, and converts back to ascii value and prints. if not in alphabet, prints as it was */
{
if (isalpha(om[i]))
{
if (isupper(om[i]))
{
int v = (int) d[i] % (strlen(d) - 1);
printf("%d", v);
printf("%c",(((om[i] - 65) + v) % 26) + 65);
}
else
{
int y = d[i] % strlen(d);
printf("%c",(((om[i] - 97) + y) % 26) + 97);
}
}
else
{
printf("%c", om[i]);
}
}
printf("\n");