The Introduction to Computer Science I for non-majors by James Tam Return to the course web page

CPSC 217: Assignment 4

New Concepts to be applied for the assignment

(Aside from storing the return value of certain string functions, lists should not be used in this assignment)

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 alphabetic text, a number and whether the program will operate in 'debugging mode' or not (see Feature #3). The text will encrypted and by shifting each character forward or backward in the alphabet depending on the size and sign of the number. A positive number shifts each character forward in the alphabet while a negative number shifts the character back.

Example: ABC, +2 (shift forward two)
A becomes C, B becomes D, C becomes E. Encrypted message = CDE

Example: ABC, -1 (shift backward one)
A 'wraps' back to Z, B becomes  A, C becomes B. Encrypted message = ZAB

Example: SUP? LOLZ, +1 (shift forward one)
S becomes T, U becomes V, P becomes Q, question mark unchanged, space unchanged, L becomes M, O becomes P, L becomes M, Z 'wraps' back to A

The only non-alphabetic characters allowed in the text include: punctuation, commas, and the apostrophe and the space character. The allowable non-alphabetic characters should not be altered (shifted). The presence of other non-alphabetic characters (e.g., a dollar sign) should result in the encryption process ending immediately at that point. Finally the program should be able to reverse the process by shifting each character in the opposite direction. The program should always display: the original text, the encrypted text and the decrypted text (which should match the original text).

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 key):

  1. Prompting the user the text to be encrypted.
  1. Prompting the user for the number and direction of shifts
  1. Prompting the user for whether debug mode is turned on (enter 'o' or 'O') to turn on. By default debug mode is off. When turned, as the program encrypts and decrypts each character the following information should be displayed in the following format:
 

Character before encryption/decryption: <ASCII code> <dash> <character> <tab> Character after encryption/decryption: <ASCII code> <dash> <character>

Example output
Original message ABC, shifts = +2
65-A    67-C
66-B    68-D
67-C    69-E

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 original text, the encrypted text and the decrypted text is displayed. If debug mode is implemented then the debugging information should appear just before the encrypted and decrypted information appear.
  Original message SUP
Encrypted message TVQ
De-rypted message SUP

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.

Example output files:

They can be found in the course directory under: /home/courses/217/assignments/assignment4

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.