You are to write a program that encrypts a message using a Caesar cipher. The us
ID: 3623755 • Letter: Y
Question
You are to write a program that encrypts a message using a Caesar cipher. The user will enter the message to be encrypted and the value of the key. An example run is shown below and your program’s output should follow this format exactly. User input is shown "Go ahead, make my day" and "3"Enter message to be encrypted: Go ahead, make my day.
Enter shift amount (1-25): 3
Encrypted message: Jr dkhdg, pdnh gdb.
You may assume that the message does not exceed 80 characters. Characters other than letters should be left unchanged. Lower-case letters remain lower-case letters when encrypted, and upper-case letters remain upper-case.
Hint: to handle the wrap-around problem for upper-case characters, use the expression
((ch-‘A’) + k) % 26 + ‘A’
to calculate the encrypted version of an upper-case letter, where k is the key (i.e., the shift amount). You will need a similar expression for lower-case letters.
Explanation / Answer
#include #include main() { char s[80]; int a,i; clrscr(); printf("enter message to be encryted: "); scanf("%s",s); printf("enter shift amount(1-25): ") ; scanf("%d",&a); for(i=0;s[i]!='';i++) { if(s[i]>='a'&&s[i]='A'&&s[i]Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.