Professional Documents
Culture Documents
The notes on Leonardo da Vincis famous Vitruvian Man image are actually in mirror writing.
The coded message is : icniV ad odranoeL 2. [16 marks in total] Mirror or reverse writing (see Question 1) can be fairly easy to decode - in fact, most people can do it on sight (which doesnt make it a very secret code!). A more advanced way of enciphering a message is to use the Caesar cipher 2 . The Caesar cipher is a type of monoalphabetic substitution cipher in which each letter in the message is replaced by a letter some xed number of positions down the alphabet. For example, with a shift of three, a would be replaced by d, b would become e, and so on; the end of the alphabet wraps around to the start. Below is the translation of each plain message character to a cipher character for a shift of three: Plain: Cipher: abcdefghijklmnopqrstuvwxyz defghijklmnopqrstuvwxyzabc
Coded messages are then formed by taking each character from the original message, looking up its cipher version and inserting it into the coded message. Plaintext: the quick brown fox jumps over the lazy dog Ciphertext: wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj (a) Draw a owchart to represent an algorithm describing a function caesar_cipher(message,shift) that takes a plaintext message of lowercase alphabetical characters and spaces stored in a string message, and shift, a value for the amount to shift each character by and returns the message encrypted using the Caesar cipher in a string. Space characters should REMAIN UNTOUCHED (as per the example above). (b) Write the function caesar_cipher(message,shift) using your owchart from part (a) to guide you. Show a screenshot of your function encoding the following message using the sum of the last digit of each group members student number as the value of the shift : the quick brown fox jumps over the lazy dog For example, with student numbers 12345, 56789 and 54321 in your group, you should use 5 + 9 + 1 = 15 as the shift amount. If you have a shift amounts greater than or equal to 26 you should subtract 25 from the amount. Hints : The MATLAB functions char and double may be useful. Also an ASCII code table may come in handy.
The Caesar cipher is named after Julius Caesar, who apparently used it with a shift of three to protect messages of military signicance.
2
(c) While being rather eective for its time, the Caesar cipher is relatively easy to break using modern computers. Two methods of breaking the cipher are Frequency analysis - where the frequency of each letter appearing in a coded message is compared with average values for the frequency of appearance of letters in typical English text. For instance, if g was the most commonly used character in a Caesar cipher coded message, it would be a reasonable assumption that it represents the original message letter e 3 . This implies a Caesar shift of 2 which can be applied to the message to test if the decoded message makes sense with a shift of 2. Brute force - where all 25 shifts are tried and printed out and the user looks at each decoded message to determine the shift used. Write a function caesar_break(ciphertext) that applies the brute force method to a lowercase message coded using the Caesar cipher and stored in the string ciphertext to print out all 25 possibilities of the shift value so that a user can easily determine the shift used in the encoding process. Your output should match the formatting below : >> ciphertext = mz qjmybxq omqemd oubtqd; >> caesar_break(ciphertext) Shift | Decoded Text ------|------------------------------------------------1 | ly pilxawp nlpdlc ntaspc 2 | kx ohkwzvo mkockb mszrob 3 | jw ngjvyun ljnbja lryqna . 12 | an example caesar cipher . 25 | na rknzcyr pnrfne pvcure where not all the shifts have been shown here to save space. Note : Your function DOES NOT need to nd the actual shift value. Use the following text below as input to your function and show a screenshot of the output it produces. mabl vbiaxk bl ptr mhh xtlr mh ukxtd What is the shift value that was used to encode the message? What is the original message?
Based on a collection of over 100, 000 characters taken from various novels and newspapers, the letter e comprises around 12.7% of characters, with the next highest being t with 9.1% and a with 8.2%.
3
3. [20 marks in total] As was explained in Question 2, monoalphabetic ciphers are prone to attack by two methods - frequency analysis and brute force. One way of reducing the vulnerability of a cipher to a frequency analysis attack is to use a homophonic substitution cipher. Basically, each message character is replaced with a variety of substitutes, the number of potential substitutes being proportional to the frequency of the letter. Oering several substitution options for popular characters helps balance out the frequencies of symbols in the coded message - thus making breaking via frequency analysis more dicult. As we are now using multiple cipher characters for a single message character, we will need to expand our cipher alphabet - in this case we will use numbers to represent the message characters. An example of a homophonic substitution cipher is given in Table 1. The rst column represents each character from the plain message alphabet, while the numbers in each row represent the cipher alphabet for each character, with several options for frequently occurring characters. (a) Write a function homophonic_cipher(message) that takes a plaintext lowercase message stored in a string message, and returns the message encrypted using the homophonic substitution cipher in Table 1 as a row vector of integers. Note : You need to ensure that you cycle through the alternative symbols in the order from the table for a message character that appears several times. For instance, the message uuuu should be encoded as [8 61 63 8]. Show a screenshot of your function encoding the following message : the attack will begin at dawn. make sure all forces are fully prepared. Hint: Dene the symbol table in Table 1 as a 28 10 matrix, where blank entries are marked as a 1. (b) Write a function homophonic_decipher(ciphertext) that takes a coded lowercase message stored in a row vector of integers ciphertext, and returns the decrypted message as a string using the homophonic substitution cipher from Table 1 to decipher. Download the script le the_secret_code.m from the LMS and put it into the same directory as your homophonic_decipher function. This script contains a secret message and when run will use your homophonic_decipher function to decipher it line by line and print it to the screen. Show a screenshot of the output of the script the_secret_code.m - i.e. the decoded secret message. What does the message say?
a b c d e f g h i j k l m n o p q r s t u v w x y z space .
9 12 33 47 53 67 78 48 81 13 41 62 1 3 45 79 14 16 24 44 46 55 57 10 31 6 25 23 39 50 56 65 68 32 70 73 83 88 93 15 4 26 37 51 84 22 27 18 58 59 66 71 91 0 5 7 54 72 90 99 38 95 94 29 35 40 42 77 80 11 19 36 76 86 96 17 20 30 43 49 69 75 8 61 63 34 60 89 28 21 52 2 92 98 97 87
64
74
82
85