Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please use basic C++ knowledge, this is a beginners course 1) Caesar cipher (60 points) Named after Julius Caesar, Caesar cipher is an encryption technique
please use basic C++ knowledge, this is a beginners course
1) Caesar cipher (60 points) Named after Julius Caesar, Caesar cipher is an encryption technique where each letter in a plain text is shifted forward some number of times to get the cipher text. For example, a shift of2 would mean, A is replaced by C, B is replaced by D, ..., Y is replaced by A, and Z is replaced by B. Notice the circular rotation among letters. Hence the plain text "Attack at midnight" would be translated to the cipher text "Cvvcem cv okfpkijv". In order to decrypt a cipher text, we would simply shift it back by the same amount. The shift amount is also called the key. Write a C program, caesar.c, to ask the user for key and the input message. Shift the input message by this key and display the result Your program must: 1. Use scanf() to input the key. Key can be any integer, positive integer implies a forward shift while negative integer implies a backward shift. Note that key of 26 is equivalent to key of 0, 27 is equivalent to 1 and so on. 2. Use getchar) to input the text from the user until they hit enter (you encounter the In' character). Assume that maximum length of input text is 100 characters IMPORTANT: While using getchar() after a scanf0, you must discard the '"n' character that the scanf) function leaves out in the input stream For each letter (A - Z and a - z) shift by the key but do not alter any non-letter character (spaces, numbers, special characters) and display the output. IMPORTANT: Remember that char type is always one byte in C, so their range is from -128 to 127. This can cause overflow of char in your program when performing addition. For example, the lowercase letter 'z' is equivalent to decimal 122 (see ASCII table), if you add more than 5 to it, you may get garbage results due to overflow. 3. Example executions: gcc -Wall -o caesar caesar.c $ ./caesar Enter a key: 5 Enter a message: Attack at MIDNIGHT Output: Fyyfhp fy RNISNLMY $ ./caesar Enter a key: -5 Enter a message: Fyyfhp fy RNISNLMY Output: Attack at MIDNIGHT
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started