Need Help ?

Home >> Assignments >> computer_science >> A Caesar cipher ( is a simple cryptographic technique

(Solved): A Caesar cipher ( is a simple cryptographic technique ...


A Caesar cipher ( is a simple cryptographic technique in which each letter is the original message is shifted to a different letter which is located at a uniform offset in alphabetical order. For example, the message “Hello World!” and offset 3 would result in an encrypted message “Khoor Zruog!” The message “Dogs and Cats” and offset -2 (which is equivalent to an offset of 24) would result in an encrypted message “Bmeq ylb Ayrq”. Note that only alphabetic characters are shifted, and that the case of the letter is preserved.

Functional requirements

Write a Unix program that takes 3 inputs from the command line: the pathname of an existing input file, the pathname of an output file to be created, and an offset between -25 and 25, inclusive. If the input file doesn’t exist, or if the output file cannot be created (perhaps because directories in its path do not exist, or because you don’t have permission to create files in the given location), or if the offset is out of range, the program prints an error message to standard error and immediately ends. Otherwise it uses the input file and offset to create an encoded output file using the Caesar cipher as described above.

Nonfunctional requirements

Implement a function,  char caesar(char s, int n) which converts a letter according to the rule given above with offset n. To avoid strange arithmetic errors use n%26 for the offset. They new char is returned. If the character is not a letter s is returned, unchanged. Use this function to process the entire file.

All the functions you write (including caesar) should be in a file caesar.c, with corresponding .h file. Main should be in its own .c file.

You may use the functions from string.h. To convert the 3rd command line argument from a string to an int, use the strtol or atoi functions from stdlib.h

We have an Answer from Expert

View Expert Answer

Get Expert Solution

caesar.cpp: #include <iostream> #include "caesar.h" char caesar(char s, int n) { while(n < 0) { n += 26; } n = n % 26;

We have an Answer from Expert

Buy This Answer $5

Place Order


Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing
Order Now