Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me with this simple C program??? Thanks!!! 1 Caesar’s code Writ

ID: 3683555 • Letter: C

Question

Can someone help me with this simple C program??? Thanks!!!

1 Caesar’s code Write a program, called caesars_code.c, to print your name using Caesar’s code. Caesar’s code works by substituting each letter with the letter that is 3 positions down the alphabet (for example, ‘A’ becomes ‘D’). When shifting the letters from the end of the alphabet you must wrap around to the beginning (for example, ‘z’ becomes ‘c’). Do not encrypt the space character.

For example:

Name: Tudor Dumitras

Encrypted name: Wxgru Gxplwudv

(Hint. Using a loop, convert each character in the string to the corresponding character in Caesar’s code. Pay attention to the difference between uppercase and lowercase characters.)

Explanation / Answer

#include <stdio.h>
#include <ctype.h>

#define MAXSIZE 1024

void encrypt(char*);

int main(void)
{

char c,
choice[2],
s[MAXSIZE];


puts("Input text to encrypt->");
gets(s);
encrypt(s);


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]=(*p + (char)3);
       else if(*p=='x')
           q[n]='a';
       else if(*p=='y')
           q[n]='b';
       else if(*p==32)
q[n]=' ';
else
           q[n]='c';
   }
   else
   {
   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 if(*p==32)
q[n]=' ';
       else
           q[n]='C';
       //q[n]=*p;
   }
   n++; p++;
   }
   q[n++]='';
   puts(q);
}