Question
Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a
Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext.
Example
Key (Shift): 3 Plaintext: Abc Ciphertext: Def
Task
Your goal is to implement a Caesar cipher program that receives the key and a paragraph (with uppercase and lowercase letters, punctuations, and spaces) and encrypt it.
Requirements
Only letters must be encrypted, any other character must remain unchanged
Note: The whole paragraph is going to be given to you as a string (char array). Review the template code for more details.
#include
#include
#include
// ---------------------- DO NOT MODIFY THIS SECTION --------------------------------
#define MAX_PGRAPH_LENGTH 100
#define MAX_WORD_LENGHT 20
int main(void) {
// definitions
char plaintext[MAX_PGRAPH_LENGTH] = "";
char ciphertext[MAX_PGRAPH_LENGTH];
char input[MAX_WORD_LENGHT];
// read the key
int key;
scanf("Key: %d,", &key);
// read text
scanf("Input: ");
while (true)
{
scanf("%s", input);
if (strlen(plaintext) + strlen(input) + 1 > MAX_PGRAPH_LENGTH)
break;
strcat(plaintext, input);
strcat(plaintext, " ");
}
plaintext[strlen(plaintext) - 1] = '\0';
// ---------------------- -----------------------------------------------------------
/
/* Put your code HERE*/
// ---------------------- DO NOT MODIFY THIS SECTION --------------------------------
printf(" Key: %d ", key);
printf(" %s ", plaintext);
printf("Output: %s ", ciphertext);
// ---------------------- -----------------------------------------------------------
}
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