The Introduction to multidisciplinary Computer Science II by James Tam Return to the course web page

CPSC 219: Assignment 1

New Concepts to be applied for the assignment

Your program must be implemented as a 'C' program (using the 'gcc' compiler) that can be compiled and executed on the Computer Science network.

Description

Encryption is the process of converting ordinary text into a form that cannot be read. Encryption is an important part of computer security. Vast amounts of information are transmitted via the Internet and wireless networks each day and we've all heard stories of systems being 'hacked' and private personal information such credit and banking information being stolen. Encrypting data before it's transmitted can prevent or mitigate ease dropping during transmission because all that will be seen of the encrypted text is gibberish. However there are good encryption algorithms and there are poor ones. Cracking or breaking the encryption is the process of trying to find the original text from the encrypted form. Good encryption algorithms make it very hard or impossible to find the original information. This is why for web browsers 128 bit encryption is superior to the older form that only uses 64 bits and for wireless computer networks why WPA replaced WEP. Decryption is the reverse of encryption and takes unreadable encrypted information and restores the original message using the original encryption algorithm.

For this assignment you will write a program that will prompt the user for a string of text and the person can choose between one of two encryption algorithms in order to 'scramble' the message. Although the algorithms that you will implement are by necessity extremely simple ones,  they should provide an insight into how encryption can be used to protect data and how poor encryption can make it easy to guess the original message. You don't need to implement a decryption algorithm for this assignment. There will be a sample executable (called "crypt") illustrating how your encryption program should work and in UNIX it can be found under the path: /home/219/assignments/assignment1

Features to be implemented (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking guide):

  1. Prompting the user the phrase to be encrypted. Ideally your program should be able to encrypt more than a single word (words will be separated by spaces).
  1. Allows the user to specify if they wish to run the program in 'debug' mode. When the program is in debug mode it not only shows the original phrase as well as the encrypted version but also the numeric ASCII value for each character in that phrase (before and after encryption). The purpose of this feature is to make it SIGNIFICANTLY easier for you and your marker to determine if your program is working. (For your reference: You can look up the ASCII  table at the UNIX command line by typing "man ascii").
  1. The user can select which encryption algorithm will be used by the program.

 
  1. Encryption algorithm I, a variation of the Caesar cipher: Normally the Caesar cipher works by shifting the letters of the alphabet forwards e.g., A become B, B becomes a C, C becomes a D...Y becomes a Z and Z becomes an A. You will need to implement the original cipher but also it should be able to shift other characters forward by one as well e.g., a number sign # has an ASCII value of 35 and after being encrypted it will become a dollar sign $ with an ASCII value of 36.ASCII codes only run from 0 - 127 so if (in theory) a character with an ASCII value of 127 were encountered the formula should 'wrap' back to the first allowable ASCII value which is 0.
 
  1. Encryption algorithm II, bitwise negation: each character in the phrase will be scrambled by the bitwise negation operator ~.
  1. The encrypted text is displayed onscreen.
  1. Instead of getting of getting the text to be encrypted from the user, this information is read from an input file (replaces feature #1).
 
  • Prompts the user for the name of the input file.
 
  • Opens and reads the text to be encrypted from file.
 
  • Program checks if there were problems opening the input file (e.g., there is no such filename) and displays an appropriate error message.
  1. Instead of displaying the encrypted text onscreen it's written an output file (replaces feature #4).

 
  • Opens and writes the encrypted text to an output file called 'encrypted.dat'.

Finally you need to decompose your programs into functions and employ (in some form) parameter passing and return values in your functions. The decomposition by function should be a fairly logical one that's well balanced between functions. For example you shouldn't name a function 'decrypt' if it actually encrypts text. Nor should you have one or more 'super' functions where most/all of the program instructions reside and a few trivial functions that do almost nothing.

Submitting your work:

  1. Assignments (source code/'dot-c' file) must be electronically submitted according to [the assignment submission requirements].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.