There might be several issues here.
- looping through your key
You're using "j" in your outer for loop to ensure doing this. I'm not sure why you initialise it with 1, though. More importantly, however, "j" gets incremented every time your outer loop executes, which is not what you want. Instead, you want to loop through your key ONLY IF the condition
is met. So, the first thing you have to do is to think about a way that ensures that you only move up one letter in your key if the character you're encoding is indeed alphabetical. You could do this, for example, by writing something like
int k = j % strlen(argv); // ensure looping of key
is met. Now, you would be using
to select the character of your key that is going to be used for encryption. Importantly, to prevent looping through your key when plain[i] is not alphabetical, try to use something like
in your for loop; the "else" statement in this case would be executed if plain[i] is not alphabetical. You decrease the value of j by one, which is then increased by one again immediately after your outer for loop has been executed again, ensuring that you remain at the same position in your key.
- Are you checking for uppercase and lowercase letters in your key?
You seem to be subtracting 65, or 'A', from every letter in your key. Think about including something like
else if (islower(argv[j]))
after you have checked for upper and lower case of your plain text.