Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the previous assignment for cat: #include #include #include #include #include #include #include //using namespace std; char script[600]; int main( int argc, char** argv

Here is the previous assignment for cat:

#include #include #include #include #include #include #include //using namespace std; char script[600]; int main( int argc, char** argv ) { int j; char data[600]; //cout << "You have entered " << argc-1 << " arguments:"; for (j = 1; j < argc; ++j) { sprintf(script, "%s %s", "cat ", argv[j]); // content stored as a C string in the buffer pointed by str. printf(" ***************Start of File******************* "); system(script); // system call to execute the command printf(" *******************End Of File******************* "); //return 0; } //int open(const char *pathname, int flags); int fd,fd1,fd2;//declaring all three here fd = open("path_to_a_file", O_RDWR | O_CREAT, 0755); if(fd == -1) { perror("opening file"); } int close(int fd); char stringbuffer[1024]; fd1 = open("read1.txt", O_RDONLY); ssize_t howmany, some_struct; howmany = read(fd1, stringbuffer, 1024); if(howmany==-1) { perror("reading file 1"); exit(1); } fd2 = open("read1.txt", O_RDONLY); howmany = read(fd2, &data, sizeof(some_struct)); if(howmany==-1) { perror("reading file 2"); exit(2); } ssize_t write(int fd, const void *buf, size_t count); char mystring[] = "Some text to write."; char * pointer = (char *) mystring; fd1 = open("write1", O_CREAT | O_WRONLY, 0777); fd2 = open("write2", O_CREAT | O_WRONLY, 0777); howmany = write(fd1, mystring, strlen(pointer)); printf("Sizeofmystring: %ld ", sizeof(mystring)); printf("strlen: %ld ", strlen(pointer)); if(howmany==-1) { perror("writing to file 1"); exit(1); } howmany = write(fd2, pointer, strlen(pointer)); if(howmany==-1) { perror("writing to file 2"); exit(2); } return 0; }

In this assignment, you will be creating an upgrade to the cat command you implemented in assignment 2. Lets call it dog because canines are so obviously better than felines. The features that will be added to this program include:

The ability to specify a command line parameter (-b x ) to change the size of the buffer used with read and write to x.

The ability to specify a command line parameter (-n x ) to change the number of bytes read from each file to ex. (Instead of reading the entire file.)

The ability to specify a command line parameter (-c x ) to change the shift to x when applying a simple Caesar cipher to text within the file (described below).

The ability to specify a command line parameter (-r x ) to specify the shift to x when applying a similar rotation to binary data within the file.

The ability to specify a command line parameter (-x ) to output the data in the file as hexadecimal numbers.

The following functions will be of use to you (read and write are mandatory).

read(2)

write(2)

getopt(3)

Requirements

The main loop should be in your main function in one source code file. The functions that perform the encryption should be found in another file. Their declarations will need to be in a header file so that they can be called from main even though their implementations are in another file.

You must make a Makefile that has rules sufficient to compile your program when a user types make in the same directory as your source code. Only files that have changed or have had their dependencies change should be recompiled.

You must use the system calls read and write to do the input and output for the program.

Obviously, your source code must be well documented. If it is not, there will be a large point penalty. This requirement holds for all assignments, whether this line is in the writeup or not.

Caesar cipher

A Caesar cipher is a very simple method of encrypting data. It involves taking the letters of the input and shifting them upwards alphabetically by a number of letters. This number will be specified as a command line parameter. If the parameter has not been specified, do not perform any shift. If it is, then your output should be shifted by that number of letters. Only letters (uppercase and lowercase) should have any shift applied at all. Leave any other characters alone. You should assume that the files are using the ASCII encoding when writing this

Binary rotation

While the Caesar cipher above was interpreting the bytes that you read as text, changing only the alphabetical charaters, this option should apply to any binary value. The principle is the same, but instead of applying it to A-Z and a-z you apply it to any one-byte binary value from 0-255.

Hexadecimal Representation

All numbers are stored as binary bits on the computer. Each char is one byte, which is 8 bits. When dealing with files that are not meant to be read by a human (binary as opposed to ASCII), it can become convenient to encode the data in a format called hexadecimal. Hexadecimal, the base-16 number system, is useful precisely because it is based on a power of 2 (24 = 16), and so each hexadecimal digit represents 4 bits. Numbers represented as decimal (base-10) do not line up in the same way. Each byte is 8 bits, so it can be written as 2 hexadecimal digits. Your program should be able to output the data in this format (2 hex digits per input byte) whenever the -x command line parameter is enabled. Keep in mind that there will be two characters of output for every character of input in this mode.

What to turn in?

When turning in the assignment, the following files should be included:

The C++ source code file containing your main function.

The C++ source code file containing the functions that implement the features enabled by command line parameters.

A C++ header (.h) file containing the declarations for each of the functions implemented.

A Makefile, The rules should be set up so that only the files that have changed need to be recompiled

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

define technical writing?

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago