Question: I need help with coding in C. Casesar Cipher (this needs to be coded in C not C++) Caesar gave his name to one of

I need help with coding in C.

Casesar Cipher (this needs to be coded in C not C++)

Caesar gave his name to one of the first ciphers ever invented.

It is a type of substitution cipher in which each letter in the plaintext is shifted a certain number of places down the alphabet. The last letters of the alphabet wrap around to the beginning of the alphabet.

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

Write program ceasar_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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!