Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

2. To compare the costs of alternative training programs.

Answered: 1 week ago