I am a beginner programmer taking a free class and I am having a lot of trouble with a simple Meyer's encryption scheme for security based encryption and decryption. I cannot work on the decryption because I cant even get the encryption to work. We are required to add necessary prompts etc to make sure the correct things are entered by the user. Here is my code:
int main (void)
{
const int N = 10;
char message [N];
char processed[N];
char selection;
void encrypt_msg(char msg[],char encrypted[]);
printf("Please enter a message: ");
fgets (message, N, stdin);
printf("%s\n",message);
printf("Would you like to encrypt <E>, or decrypt <D> this message?");
scanf(" %c\n",&selection);
if (selection == 'E')
{
encrypt_msg(message,processed);
printf("%s\n",processed);
return 0;
}
if (selection != 'E')
{
printf("Invalid selection, please enter <E> or <D> ");
}
}
void encrypt_msg(char msg[],char encrypted[])
{
int i;
int NL;
for (i=0;msg[i]!='\0';i++)
{
while (msg[i]<'z'&&msg[i]>'A')
{
NL=msg[i]+i+1;
while (NL<'z')
{
NL=NL;
}
while(NL>'z')
{
NL=NL-26;
}
encrypted[i]=msg[i]+1;
}
}
}
The problem is that when the user inputs "E", the program will immediately go to the "invalid input" if statement and bypass the actual encryption function. It may be doing something entirely different but I don't know because I am horrible. 'NL' is for the new letter that is to replace the old letter based on the M.E.S.S key.