Lecture notes for 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

Part I:

 

  • Problem solving in 'C'

 

  • Writing program documentation

 

  • Decision making/branching

 

  • Loops/repetition

 

 

Part II:

 

  • Homogeneous lists: ('C' style arrays)

 

  • Using/implementing low level (bit level) operations

 

  • Simple encryption algorithms

 

  • Testing and debugging using debugging flags

 

Both parts must be implemented as 'C' programs that can be compiled and executed on the Computer Science network.

 

Part I: Rock-Paper-Scissors

This is a simple two player game where each player is allowed one of three possible hand gestures: rock, paper or scissors. This is a turn based game and players select their gesture one after the other. The gesture selected determines the outcome:
Player 1 Player 2 Outcome of the game
Rock Rock Tie
Rock Paper Paper covers rock (player 2 wins)
Rock Scissors Rock blunts the scissors (player 1 wins)
Paper Rock Paper covers rock (player 1 wins)
Paper Paper Tie
Paper Scissors Scissors cuts paper (player 2 wins)
Scissors Rock Rock blunts the scissors (player 2 wins)
Scissors Paper Scissors cuts paper (player 1 wins)
Scissors Scissors Tie

If a player tries to cheat (e.g., gives an invalid gesture) then that player has committed a foul and is given a "forced rock" for their gesture.  To get more familiar with the game you can try a web based version here http://www.playrps.com/. Also you can find a sample executable called 'rps' in UNIX 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. Each time that the game is run (but not re-run, see feature #8) it displays an introduction to game with a brief description of the rules.
  1. When the player quits the game it displays a brief conclusion/signoff message.
  1. Displays a menu of allowable gestures when each player is prompted to select their gesture.
  1. Reads each player's selected gesture in the form of a single lower case character.
  1. The game can check if a foul has occurred (in this case the player has not entered 'r', 'p' or 's' for their selected gesture and will give the fouling player the rock gesture for that round.
  1. Upper or lower case input is allowed  (e.g., 'R' or 'r').
  1. Compares the gestures for the players and can correctly determine and display onscreen: which player is the winner, which player is the loser or if there is a tie.
  1. After a turn has been played (the player's select their respective gesture and the game determines the outcome), the program will ask the player if he or she wishes to play again and play another turn if this is the case or end the game and display a signoff message otherwise.
  1. The game tracks and displays the number of wins and loses for each player.

 

Part II: Encryption

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 give you 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 but you will probably do so for the next one. 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. Read from 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. 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 ~.

 

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.