First Bytes at the Honors Colloquium

Caesar Cipher Lab - Part 3

Introduction: In this lab activity you will use MatLab and write functions to decrypt a message that is encoded with a Caesar cipher and the shift is unknown.

This lab is available at www.cs.utexas.edu/users/scottm/FirstBytes/caesarLabPart3.htm

In the previous 2 labs the shift for the encoded message was known. This made it relatively easy to decode the message. Normally though the shift is not known? Can we still break a Caesar cipher? The answer is yes, and with a computer it can be broken relatively quickly. The reason is that with an alphabet of 26 letters there are in fact only 25 possible keys and a brute force approach would be to simply try all 25 possible shifts and look for any message that makes sense.

To complete this lab create a new function that only takes in one input, the message to be decoded.

    function result = allshifts(message)

This function should use the function from part 2 and call it 25 times, once for each possible shift. You can add the results from your single shift function using the following syntax

    result = message

    later in loop

  result = [result;temp]

This assumes temp holds the answer of the single shift. The syntax above creates a new matrix with the old matrix plus temp as the new last row. 

The first message for this lab is:

YVSRJNFZRNAGGBORYVIRQNAQPHEVBFVGLZHFGORXRCGNYVIRBARZHFGARIRESBEJUNGRIREERNFBAGHEAUVFONPXBAYVSRRYRNABEEBBFRIRYG

The second message is:

QSNNMQGLEDMPGLQRYLACRFYRRFCDSLBYKCLRYJPCJYRGMLQMDNGRAFCBQMSLBQGLRFCQAGCLACMDFYPKMLWYLBMDKSQGAYJAMKNMQGRGMLUCPCQSQACNRGZJCMDQSAFCVNPCQQGMLYLBYBYNRYRGMLQRFCCLEGLCKGEFRAMKNMQCCJYZMPYRCYLBQAGCLRGDGANGCACQMDKSQGAMDYLWBCEPCCMDAMKNJCVGRWMPCVRCLRYBYJMTCJYAC

The messages are on the web at

www.cs.utexas.edu/users/scottm/FirstBytes/caesar4.txt

and

www.cs.utexas.edu/users/scottm/FirstBytes.caesar5.txt