Question: In C please In this lab, you will implement a simple command-line Caesar cipher for all the printable characters (not just A to Z) in

In C please

In this lab, you will implement a simple command-line Caesar cipher for all the printable characters (not just A to Z) in the ASCII code, which are conveniently contiguously ordered. While the C programming language does not insist the ASCII coding is used for the integer values of its char types, this lab will rely on it with the following assumptions:

  • The printable characters are all contiguous
  • The space ("") is the first (lowest integer value) printable character
  • The tilde ("~") is the last (highest integer value) printable character

With these assumptions we can encrypt the 95 printable characters in the ASCII code. Note we can calculate this number by the following calculation (which we make use of in the template program).)

const int NUM_CHARS = ('~' - ' ') + 1; 

Your lab should include the function

char cipher(char in, int shift) 

which would take a given (printable) character in and return the resulting character moved by the amount shift (which could be negative). The values should wrap around.

Example Output
cipher('#',1) '$'
cipher('X',10) 'b'
cipher('z',8) '#'
cipher('g',-5) 'b'
cipher(' ',-1) '~'

Use this function in a program that takes at least two command line arguments. The first should correspond to an integer shift amount, and the rest should be strings to be encrypted by that shift amount. Your program should print the space-separated encrypted strings.

You should use sscanf (see section "Input parsing" in chapter 9) to parse the shift amount.

If insufficient arguments are given, your program should print following the message and terminate.

Usage: run key word [word ...] 

If an integer cannot be extracted from the argument in position 1, your program should print the following message and terminate.

Expected integer for key. 
Example Output
run 3 Hail, Caesar! Kdlo/ Fdhvdu$
run -3 Kdlo/ Fdhvdu$ Hail, Caesar!
run 63 output OUTPUT
run 124 "better schemes" #22#0=1!&#+#1

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!