Project 1 – Bitwise Encryption

Due: Monday, October 2nd

By the start of class (9:00 am)

 

 

Introduction

 

In class we’ve learned that both bitwise NOT and bitwise XOR can be used to reversibly alter data so that it is hidden from others.  In this project you will create two programs, one using NOT and one using XOR to make simple encryption utilities.

 

Setup

 

Make a directory called project1 under your private/cs132 directory to do all of your work in. The submission instructions will assume you did this.

 

Bitwise NOT

 

Write a program called project1a.c that reads in a single line of input from stdin and bitwise NOTs each character, printing the resultant text to the screen.

 

Notice that the text displayed is mostly junk. We can capture that to a file using the output redirection command, and feed it another file using the input redirection command. Create a sample file using pico that contains one line of text and call it test1.txt We can encrypt it and save the output by executing the command:

 

./project1a < test1.txt > test1.enc

 

And the output will be saved to the file test1.enc  Open this file in pico and examine the contents. It should no longer be readable.

 

Since bitwise NOT is symmetric, we should be able to use test1.enc as input and get the text back that was in the test1.txt file. Try it:

 

./project1a < test1.enc

 

Bitwise XOR

 

Write a new program called project1b.c that again reads in a single line of input from stdin and bitwise XORs each character with a character of your choice (called a “key” in encryption terminology.)

 

Run it as we did with project1a.  Play around with various choices of input text and keys. In some circumstances it may be the case that the output you get while decrypting it is a truncated version of the original text. In a comment in project1b.c, explain why this might be happening based on your knowledge of what Bitwise XOR does and how strings in C are represented.

 

What to turn in

 

Make sure that you turn in project1a.c, project1b.c, and at least two input files, one of which demonstrates the truncation problem in part b. Don’t forget to put your explanation of the problem in a comment in the source file.

 

Submission instructions

 

In the project1 directory do a

 

rm *.o

 

to remove the object files compilation creates.

 

Go back up to the cs132 directory and issue the following command:

 

tar cvf LASTNAME.tar project1

 

where LASTNAME is your last name. NOTE: If you autocomplete project1 with TAB, a slash will appear at the end, you need to delete this slash for tar to work.

 

Now copy your tarball to the submit directory:

 

cp LASTNAME.tar ~jrmst106/submit

 

If you want you can cd to the submit directory and do an ls to see if it is actually there.