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

Please complete this C coding program in full. Thanks!! Check out the example of

ID: 3876076 • Letter: P

Question

Please complete this C coding program in full. Thanks!! Check out the example of the program output, which is the last image.

In this assignment you will use your knowledge of strings to write a program that will encrypt/decrypt messages Your program should: - ask the user whether they want to: Change shift value, make sure you set it to 3 by default, although I don't reccommend going higher than 4 Encrypt a message Decrypt a message Quit - the user should then be able to type in a message up to 500 characters in length that will be encrypted/decrypted and "shifts" that value a certain amount of places to change its value selects the option to quit. - you will use what is called a shift cipher to encrypt the messages - a shift cypher takes your input and goes through it one letter at a time -Your program should continue to bring up the main menu until the user

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int getShift( void )
{
int i;
printf ("Enter new shift value: ");
scanf ("%d", &i);
printf (" ");
return i;
}

void banner (void)
{
printf ("------------------------------- ");
printf ("| 1) Change Shift (default 3) | ");
printf ("| 2) Encrypt a message | ");
printf ("| 3) Decrypt a message | ");
printf ("| 4) Quit | ");
printf ("------------------------------- ");
fflush(stdin);
}

int getUserChoice (void)
{
int i;
scanf ("%d", &i);
return i;
}

void getString (char buf[])
{
char t;
printf ("Input: ");
scanf ("%c", &t);
scanf ("%[^ ]s", buf);
return;
}

void encrypt (char buf[], int shift)
{

int len = 0, i;
len = strlen (buf);

for (i=0; i<len; i++)
{
buf[i] = buf[i] + shift;
}
printf ("Output: %s ", buf);
return;
}

void decrypt (char buf[], int shift)
{
int len = 0, i;
len = strlen (buf);

for (i=0; i<len; i++)
{
buf[i] = buf[i] - shift;
}

printf ("Output: %s ", buf);
return;
}

#define MAX_BUFF 500 /*Change your input buffer as per your requirement*/

int main()
{

int option;
char buf[MAX_BUFF] = {''};
int shift = 3; /*Default Shift 3*/

while (1)
{
banner ();

printf ("Option: ");
option = getUserChoice();
memset (buf, '', MAX_BUFF);

switch (option)
{
case 1:
shift = getShift();
continue;

case 2:
printf ("In 2 .. ");
getString(buf);
encrypt (buf, shift);
continue;

case 3:
printf ("In 3 .. ");
getString(buf);
decrypt (buf, shift);
continue;

case 4:
return 0;

default:
printf ("Invalid Choice, try again ");
continue;
}
}


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote