File encryption

Object

To test understanding of I/O (input output) functions for file handling, and to use the bitwise operators.

Task description

This program consists of two parts: encryption of a file, and decryption of a file that has been previously encrypted. Encryption is the process of rendering a text file unreadable by humans, yet by applying the process in reverse (decryption) the file can be recovered in its original state.

It may be implemented by two functions, one to do the encryption, and the other to do the decryption. The main program should accept the following as part of the command line:

The program should check the arguments on the command line and give help to the user as to how to run the program if there are insufficient arguments, or any incorrect ones.

So, if you compile your program using command:

% gcc -o  crypt  cryption.c

(assuming your C program is in the file cryption.c), to encrypt an input text file named tfile and store the encrypted output as efile, you could type the

command:

% crypt e password tfile efile

(where password is the password for encryption, and e indicates encryption is to be done)

Subsequently, you will run the program again to decrypt the encrypted file as input (using the same password); you should get the original text file back as output.

% crypt d password efile tnewfile

where password is the password for decryption, and d indicates decryption is to be done.

Note : after the two runs of the program: the contents of tnewfile should be IDENTICAL to that of tfile. An easy check for this is to use the UNIX program diff:

% diff tnewfile tfile

This should produce no messages, since a message of any kind indicates a difference between the two files.

Procedure

  1. Write a problem statement and description, taking care to discuss the limitations of your program.
  2. Draw a TDSR diagram showing the breakdown of the parts of you program.
  3. Write and compile the program.
  4. Test the program by encryption and decryption to (hopefully) return the same file. The program should be able to read any text file--test your program on small files first that can be checked by hand.

Hints

Deliverables

  1. The problem statement, description and TDSR design diagram.
  2. The completed source code.
  3. A sample input file and the same file after encryption and decryption. The listings should be identical. There is no need to show the encrypted file since it should bear no resemblance to the input and will probably contain non-printing characters anyway.

Due date

April 30th., 5:00pm. Mail your completed source code to the grader, (login salahmed). Hand in the hard copy version to me (RTH), together with a hard copy version of the output.