The c program will implement the Caesar Cipher Your program
\" The c program will implement the Caesar Cipher. Your program should take a command line argument, which will be the offset, while the input through standard in will be the part that will be rotated(encrypted/decrypted). To simplify this assignment you will only need to rotate characters that are alpha characters (letters). No other characters should be rotated. You can also assume that the input will only be a single line long. Your script will take a single command line argument, which will be the rotation argument to the Caesar c program you wrote above. Your script should then call the \"Program2_2.\" you wrote each of the .enc files. Your script should output a .dec file for each .enc file that exists. \"
Solution
#include <stdio.h>
#include <ctype.h>
#define MAXSIZE 1024
void encrypt(char*);
void decrypt(char*);
int menu();
int
main(void)
{
char c,
choice[2],
s[MAXSIZE];
while(1)
{
menu();
gets(choice);
if((choice[0]==\'e\')||(choice[0]==\'E\'))
{
puts(\"Input text to encrypt->\");
gets(s);
encrypt(s);
}
else if((choice[0]==\'d\')||(choice[0]==\'D\'))
{
puts(\"Input text to decrypt->\");
gets(s);
decrypt(s);
}
else
break;
}
return 0;
}
void encrypt(char*str)
{
int n=0;
char *p=str,
q[MAXSIZE];
while(*p)
{
if(islower(*p))
{
if((*p>=\'a\')&&(*p<\'x\'))
q[n]=toupper(*p + (char)3);
else if(*p==\'x\')
q[n]=\'A\';
else if(*p==\'y\')
q[n]=\'B\';
else
q[n]=\'C\';
}
else
{
q[n]=*p;
}
n++; p++;
}
q[n++]=\'\\0\';
puts(q);
}
void decrypt(char*str)
{
int n=0;
char *p=str,
q[MAXSIZE];
while(*p)
{
if(isupper(*p))
{
if((*p>=\'D\')&&(*p<=\'Z\'))
q[n]=tolower(*p - (char)3);
else if(*p==\'A\')
q[n]=\'x\';
else if(*p==\'B\')
q[n]=\'y\';
else
q[n]=\'z\';
}
else
{
q[n]=*p;
}
n++; p++;
}
q[n++]=\'\\0\';
puts(q);
}
int menu()
{
puts(\"To encrypt, input e or E\ \");
puts(\"To decrypt, input d or D\ \");
puts(\"To exit, input any other letter\ \");
puts(\"Your choice:->\ \");
return 0;
}

