Write a C program that will encrypt and decrypt messages using a basic shift cip
ID: 3662666 • Letter: W
Question
Write a C program that will encrypt and decrypt messages using a basic shift cipher. This cipher works by simply shifting the characters of the string by a known number. For example, if we shift the string "programming" by one letter, we would get "qsphsbnnjoh"
The letter after p is q The letter after r is s The letter after o is p ... and so on
Your program should:
-ask the user if they want to encrypt or decrypt a message
-ask the user for a numerical "key" value by which to shift the characters
-let the user type in a message up to 500 characters in length that will be encrypted or decrypted
-use at a minimum:
-functions -strings -loops
-if statements
Recommended functions to get you started: -encrypt
-decrypt
-getUserInput
Explanation / Answer
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i;
char str[30];
clrscr();
printf(" Enter any string : ");
gets(str);
for(i=0; str[i]!=''; i++)
{
if(str[i]>='a' && str[i]<='z')
{
str[i]=str[i]+1;
}
printf("%c",str[i]);
}
getch();
}
Output:
Enter any string : programming
qsphsbnnjoh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.