Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C program USING THE OUTLINE PROVIDED BELOW: A caesar cipher is a simple cipher that shifts letters in a string. For example, shifting

Create a C program USING THE OUTLINE PROVIDED BELOW:

A caesar cipher is a simple cipher that shifts letters in a string. For example, shifting ab over by 1 would result in bc, and shifting xyz over by 2 would result in zab. The caesar program should take, in the command line an integer k, the amount to shift some text by, and a string f i l e, the name of a file containing text to encode using the cipher.

For example, suppose secret.txt contains defend the east wall of the castle, then running caesar with 3 should result in the following:

$ cat secret.txt

defend the east wall of the castle

$ ./caesar 3 secret.txt

ghihqg wkh hdvw zdoo ri wkh fdvwoh

HERES THE OUTLINE:

#include #include

/* This is a prototype for a function. * You should implement it below, not here. */ void caesar(long sz,char buf[sz],int shift);

/* Obtains the filesize by "seeking" at the end and restoring the seek pointer * to where it used to be before the call to filesize. */ long fileSize(FILE* f) {

fseek(f, 0, SEEK_END); long size = ftell(f); rewind(f);

return size; }

void caesar(long sz,char buf[sz],int shift);

/* Read the file into an array and use the caesar encoder with the specified shift * - f : the file to read from * - shift : the shift in the cipher [http://practicalcryptography.com/ciphers/caesar-cipher/] * Hint: use fileSize to figure out how much space you need. * Caesar never sent very long messages to his generals ;-) */ void readAndEncode(FILE* f,int shift) { /* Implement! */ }

/* The actual caesar encoder. Input is: * - sz : the buffer size * - buf : actual buffer * - shift : how much to shift by */ void caesar(long sz,char buf[sz],int shift) { /* Implement! */ }

/* Main program. Input on command line (2): * - first the shift * - second the filename of the secret to be encoded * Do error checking (we need 2 inputs) * The shift should be in (0..26) * We should have a filename * Print the encoded message on the standard output */ int main(int argc,char* argv[]) { if(argc != 3) { printf("usage: caesar "); return 1; } int shift = atoi(argv[1]); char* fName = argv[2]; if (shift < 0 || shift > 26) { printf("caesar shift should be a value in [0..26] "); return 1; }

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

7. Discuss the advantages of embedded learning.

Answered: 1 week ago