Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program Caesar Cipher For example, with a shift value of 3, A would be replaced by D, B by E, , X by A,

C Program Caesar Cipher

For example, with a shift value of 3, A would be replaced by D, B by E, , X by A, and so on. See figure below for graphical example.

Write program caesar_cipher.c that first reads a key (i.e. a shift value) and then ciphers every inputted line, as illustrated in the following example.

$ cat plaintext 3 Hello world, My name is *R2D2*! $ ./caesar_cipher < plaintext Khoor zruog, Pb qdph lv *U2G2*! $ cat ciphertext 11 Xu ndj lpci id qt wpeen, qt. -Atd Idahidn $ ./caesar_cipher < ciphertext If you want to be happy, be. -Leo Tolstoy $ ./caesar_cipher -5 Invalid key $ echo $? 1 $ 

If the inputted key is negative or greater than 26, it should be signalled as invalid.

Your code should follow certain constraint(s):

There should be a cipher function that implements the following prototype:

void cipher(int key, char *c); 

This function takes in the key (i.e. the shift value) and an input/output parameter representing the character to cipher and that the function must modify according to its value.

The character to cipher can be an uppercase or lowercase character, and the alphabet wrapping should be properly handled.

Your program should analyse characters one by one from the input, which means that you should not use an array or a string. When EOF is encountered, the program should terminate.

Characters that are not printable or that are not spaces (see ctype.h) should simply be ignored.

Only alphabetic characters should be ciphered, other characters should be left unmodified.

Hint(s):

After reading the key from the user with scanf(), a newline character will be left in the input buffer. You can call the function getchar() once before your main loop in order to get rid of it.

EOF can be emulated with the keyboard by pressing Ctrl-D.

Leave comments showing how code works if possible

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago

Question

=+1 Is the decision fair to employees?

Answered: 1 week ago