I was having issues with my for loop, but with the help and guidance of
fellow coders in here I was able to fix most of it.
I managed to do the caesar cipher and I used it as a frame of reference.
Now my code is working when it's lower case but I'm having issues with the upper case condition
here is my updated
code:
for ( int i = 0 , j = 0 ; i < strlen(text) && j < key[j % strlen(key)] ; i++, j++ ){
// check if it's lower case
if (islower(text[i])) {
printf("%c", ((text[i] - 'a' + key[j] - 'a') % 26 + 'a'));
j++;
if (j == strlen(key)){
j = 0;
}
// check if it's upper case
} else if (isupper(text[i])) {
printf("%c", ((text[i] + 'A' + key[j] + 'A') % 26 + 'A'));
j++;
if (j == strlen(key)){
j = 0;
}
}
When I compile my program and give it :
./vigenere bacon
Meet me at the park at eleven am
instead of having this:
Negh zf av huf pcfx bt gzrwep oz
I get this wrong answer with everything is correct except the 1st uppercase encryption
:
Tegh zf av huf pcfx bt gzrwep oz