CSC3320 Assignment 3 25 points due 3/15/02 Dr. Harrison Spring 2002
This assignment consists of two C programs and an awk script. When complete it should be emailed to the GTA in ONE email (use either attachments (preferred -use pine) or a tar file). His account is slp40@yamacraw.cs.gsu.edu. Printed copies of the files should also be handed to me.
Write a program that accepts a one-byte hex format number (00-FF) and uses that to encrypt a file with XOR. The program will be similar to the example in Dr King's book on pp 456-457, except you will use the C-library to open a file and read it in an binary form (either with read() or with fread()). You will also use write() or fwrite() to write the file in a binary form. It should encrypt all the characters in the file, spaces as well as non-space characters.
Write a program to recover the key from a file encrypted with the first program. Read the encrypted file and find the most common single characters and pairs of characters. If the file was originally in English the most common 6 characters will be '<space>etoan' and the most common non-space pairs will be 'th', 'he', 'an' and 'in' . XOR the most common single character with each of the letters in '<space>etoan' and the use that possible key to decrypt the most common pairs. The correct key will decrypt all the pairs to printable strings. Print out the 6 possible keys and their decrypts of the common pairs (which may contain spaces). Print a number (like the od utility does) if the decrypt is not printable (i.e. not a letter or space).
Write an
awk program to find the mean and variance of a set of input data.
Assume that the data are in the second column of the input. (the
mean is the sum of all the data values divided by the number of data
points
and
the variance is the mean square minus the square mean
(we'll
ignore the square root of the whole thing) ).