Week 06 Laboratory Exercises


  • unused Lab from flex week

Activities To Be Completed

The following is a list of all the activities available to complete this week...

Worth one mark in total:

Worth half a mark in total:

Worth half a mark in total:

For your interest, but not for marks:


Before the lab you should re-read the relevant lecture slides and their accompanying examples.


WWII code-breaking at Bletchley Park, spearheaded by Alan Turing (amongst many others), was the genesis of modern computing. In this lab you too will perform computer-assisted code-breaking but don't worry, the ciphers you must break are simpler than the German Lorenz and Enigma ciphers.

The two ciphers we'll be looking at in the lab are the Caesar cipher and the Substitution cipher.

The Caesar Cipher is a way of encrypting text by "rotating" the letters through the alphabet so that each letter in a message is an exact number of letters away from its original.

The Substitution Cipher is a way of encrypting text by replacing each letter with a specific other letter in the alphabet.

The exercises in the labs require you to read characters. Use the library function getchar to do this.

getchar reads the next character from standard input and returns it. If getchar is unable to read a character it returns the special value EOF.

When input is coming from a file, getchar will return EOF after the last character in the file is read.

When input is coming from a (Linux/OSX) terminal, you can indicate no more characters can be read by typing Ctrl+D. This will cause getchar to return EOF

In some of this week's lab exercises you will find it convenient to put the test input in a file, rather than type it every time you want to test the program.

You can use a < character to indicate to the shell that you want to run a program taking its input from a file.

So for example you might create the file input.txt with gedit and then run a.out takes its input from the file rather the terminal:

gedit input.txt &
./a.out <input.txt


When you are finished each exercises make sure you submit your work by running give.

You can run give multiple times. Only your last submission will be marked.

Don't submit any exercises you haven't attempted.

If you are working at home, you may find it more convenient to upload your work via give's web interface.

Remember you have until Wednesday 01 December 00:00 to submit your work.

You cannot obtain marks by e-mailing your code to tutors or lecturers.

You check the files you have submitted here.

Automarking will be run by the lecturer several days after the submission deadline, using test cases different to those autotest runs for you. (Hint: do your own testing as well as running autotest.)

After automarking is run by the lecturer you can view your results here. The resulting mark will also be available via give's web interface.

Lab Marks

When all components of a lab are automarked you should be able to view the the marks via give's web interface or by running this command on a CSE machine:

1511 classrun -sturec