C Program Type a program in C to encode the message with Caesar's cipher. Your program will receive a text message, and the key value will then generate an encryption text for the given message. example: Enter a message to encrypt: axzd Enter key: 4 Encrypted message: ebdh **Make sure your program can check that the given message is not empty AND Your program must include a helper function that accepts the input message and checks that it contains only characters before generating the ciphertext
#include<iostream>
using namespace std;
int main()
{
char message[100], ch;
int i, key, check=0;
printf("Enter a message to encrypt: ");
do{
gets(message);
check=helper_fun(message);
} while (check== 0 || message.empty());
printf("Enter key: ");
scanf("%d", &key);
for(i = 0; message[i] != '\0'; ++i){
ch = message[i];
if(ch >= 'a' && ch <= 'z'){
ch = ch + key;
if(ch > 'z'){
ch = ch - 'z' + 'a' - 1;
}
message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + key;
if(ch > 'Z'){
ch = ch - 'Z' + 'A' - 1;
}
message[i] = ch;
}
}
printf("Encrypted message: %s", message);
return 0;
}
int helper_fun(char s[100] )
{
int i,F=0;
For(i=0;i<s.length();i++)
{
If(isalpha(s[i])!=0)
F=1;
}
If(F==0)
return 1;
else {
cout<<”contains characters other than alplabets or letters”;
return 0;
}
}
Please make changes according to your ide.
Get Answers For Free
Most questions answered within 1 hours.