600.120 Intermediate Programming
Spring 2010 -- Assignment 1
Due Tuesday, 2/9 by 2:45pm

If you haven't already, make sure you get your CS Unix account and test your programs there!

The Problem: Simple Encryption

Write a program that uses the bit operators to perform two different forms of simple encryption on a single line of plain text input. In both forms, you will be applying transformations to individual characters in the text. For the purpose of this assignment, you may assume that no line of input contains more than 80 characters. (Make sure that the 80 limit is something that can be changed easily within your program.)

The first type of transformation is to perform a one's complement of each non-space character using the ~ bit operator. All whitespace characters should remain intact. Then display the message using whatever characters result from the bit transformation. The cool thing about this particular encryption is that in order to decrypt a message you perform the same operation. It is its own inverse.

The second type of transformation is to perform a left bit shift to encrypt each character, including any whitespace. The shift value must be an integer which is less than the number of bits in a char variable. Prompt the user to enter this value, given an appropriate range. Do error checking on this input. However, you will need to store the characters in an integer data type that is twice as large as the character type in order to not lose significant bits when shifting. (Use the sizeof function to determine exactly which data type is most appropriate, and consider using a unsigned type for the best results.) With this transformation, you must display the encrypted values as integers, not as characters, separated by spaces. In order to decrypt this type of message, simply do a right bit shift using the same shift value.

The overall operation of your program should be as follows:

You must have at least three functions in your program: 1) create the one's complement of a character array, 2) encrypt a message using a left shift, 3) decrypt a message using a right shift. It is up to you to determine what parameter types and return values (if any) work best for these methods. Use other functions in your program to make the most of code reuse and good structured programming. You must not use any global variables.