Sherlock Holmes and the adventures of the dancing men Kseniya Garaschuk May 30, 2013 1 Overview Cryptography (from Greek for hidden, secret ) is the practice and study of hiding information. A cipher is a pair of algorithms that create the encryption (the process of converting ordinary information into unintelligible gibberish) and the reversing decryption - all using a secret key. Without knowing the secret key, it is difficult, if not nearly impossible, to decrypt the message. In this workshop, students will get acquainted with many different kinds of ciphers. We will start off by introducing historical ciphers, such as scytale transposition cipher claimed to have been used by the Spartan military and Caesar substitution cipher, used by its namesake to communicate with his generals during his military campaigns. We will then discuss the Vigenère cipher - a combination of 26 possible Caesar ciphers. We will then proceed to introduce the transposition ciphers in which the letters remain unchanged, but message is scrambled in a sophisticated way. We will analyze all the ciphers and learn how to break them. 2 Instructions and explanation of the format Below you will see detailed explanation of the material that should be presented to the students as well as various activities and challenges. Activities are for the students to practice the material. Brainstorm idea are for you to suggest or get from the audience and discuss. Extra activities are bonus in case some students work faster than others, these will prevent students from getting bored. Challenges are rewarded by clues to the mega puzzle! 1
The mega puzzle consists of the attached clues of dancing men. Students are told (in a skit or otherwise) that they are privy to secret communication between imprisoned Augustus Carmichael and Slippery Pete, his pirate partner on the outside. At the very beginning students are given the first two lines of the code. After completing the first challenge, the students are given the rest of the first page of clues. After completing the second challenge, the students are told that flags represent the ends of words (you will have to draw those in before photocopying the clues!!). After completing the third challenge, the students are given the final clue. The clues read: I hid the treasure at UVic. Keep it a secret. Make sure you are not followed. Tell pirate the password to get the map. Password is vacuum. (Do not forget to draw flags in!) After telling the pirate (someone will have to dress up), the pirate gives them the campus map where X makes the spot where treasure (aka candy) is hidden. 3 Substitution ciphers Idea: each letter that you want to encipher is substituted by another letter or symbol, but the order in which the letter appear is kept the same. Example 1 (Caesar cipher). Julius Caesar (100-44 BC) used this cipher in government communications. This cipher was less strong than other methods, by a small amount, but in a day when few people read in the first place, it was good enough. Activity 1. Decipher the following: D pdwkhpdwlfldq lv d ghylfh iru wxuqlqj friihh lqwr wkhruhpv. (A mathematician is a device for turning coffee into theorems.) Brainstorm ideas: Look for short words first; there are only two one-letter words in English and very few two-letter words (what are they?). Also, each word in English must have a vowel in it. Look for doubled letters. Frequent doubles are ss, ll, oo, ee, nn, pp. Hardly ever do you see aa or yy, and uu (unless the message happens to be about vacuums!) A more advanced technique is called frequency analysis, which is used to break ANY simple substitution cipher. To use this, count the occurrences of each of 2
the letters in the ciphertext (e.g., 17 X s, 12B s, 9 C s, 7 P s, etc.). Then look at a standard English frequency table. Activity 2. How can we make encoding faster with Caesar cipher? ideas. Create cipher disk. Brainstorm Challenge 1. Work as a team. Use cipher disk for speed to decipher the following: Zngu vf ab zber pbzchgngvba guna glcvat vf yvgrengher. (Math is no more computation than typing is literature.) Extra activity 1 (Atbash cipher). The cipher used in this message is another substitution cipher. It s not a rotation of the alphabet, so you cannot use the cipher disk. There is, however, a pattern to it (the alphabet is reveresed). Decipher the following: LYERLFH RH GSV NLHG WZMTVILFH DLIW RM NZGSVNZGRXH (Obvious is the most dangerous word in mathematics) Questions for thought: What if you didn t have any word breaks? Use frequency analysis. What else would make this harder to break? Since frequency analysis uses the fact that letters (like e ) are repeated regularly, you can instead replace e with several different symbols (say, 12 of them), so that each symbol only shows up one percent of the time. If you do this for the highest frequency letters, the cipher is much harder to crack! You can also have entire words replaced by certain symbols, especially ones that come up often and contain high-frequency letters (the words the and and, for example) or you can replace important words (like midnight if you message was attack at midnight ). That way, the frequency analysis is thrown off and some words remain hidden even after most of the cipher is broken. Another option is to insert nulls symbols that don t stand for anything at all! If you have a wide enough variety of nulls in your cipher, it can be pretty hard to crack! 3
4 Vigenère cipher Above ciphers are monoalphabetic substitution ciphers - ones which were encoded using only one fixed alphabet (hence the Greek root mono meaning one ). As we saw, especially when the spaces between words are still there, these are fairly easy to break. So, how can you make this harder? Use more than one alphabet, switching between them systematically! This type of cipher is called a polyalphabetic substitution cipher ( poly is the Greek root for many ). The difference is that frequency analysis no longer works the same way to break these. One such cipher is the famous Vigenère cipher, which was thought to be unbreakable for almost 300 years! It uses the power of 26 possible shift ciphers. How this Cipher Works: Pick a keyword (for our example, the keyword will be MEC ). Write your keyword across the top of the text you want to encipher, repeating it as many times as necessary. Now each block of 3 letters is shifted by a key-word. Word MEC consists of the 13th, 5th, and 3rd letters of the alphabet, then the first letter of the message is shifted by 13, the second letter is shifted by 5, the third by 3, the fourth by 13 (here we return to the beginning of the key-word), the fifth by 5, and so on. (Alternatively, use the Vigenère table for faster lookup or a slide ruler). Example: M E C M E C M E C M E C M E C M E C M E C M w e n e e d m o r e s u p p l i e s f a s t I I P Q I F Y S T Q W W B T N U I U R E U F So, as you can see, the letter e is enciphered sometimes as an I and sometimes as a Q. Not only that, but I represents two different letters, sometimes a w and sometimes an e. This renders our favorite tool, frequency analysis, nearly useless. Even though e is used very often in the plaintext, the letters that replace it ( I and Q ) don t show up as frequently. Also, now if we check doubled letters in the ciphertext (say II or WW ), these are not doubled letters in the plaintext. 4
You may, then, ask yourself is there any hope? Fortunately, there is! Given a long enough piece of ciphertext, certain words or parts of words (like the ) will line up with the keyword several times, giving rise to a repeated string of letters in the ciphertext. This can give us a clue as to the length of the keyword. After that, we can use frequency analysis on each piece that was enciphered with the same letter to crack the code. Consequently, cracking these ciphers hinges on finding repeated strings of letters in the ciphertext. Challenge 2. Give them first ciphertext and first key. They bring back ciphertext. Give them second key. They bring back final plaintext. H O C U S P O C U S - first ciphertext h b c t a p e y s m - first key O P E N S E S A M E - second ciphertext e t i f i h i b w i - second key S I M S A L A B I M - final answer Extra activity 2 (Keyed cipher disk). You can use a key for the construction of cipher disk and, hence, a modification of both Caesar and Vigenère ciphers. Pick a word with no repeated letters, for example CIPHER. On the inner disk, instead of standard alphabet, first write the keyword and then write the remaining letters of the alphabet. So on our inner disk we will have: CIPHERABDFGJKLMNOQSTU- VWXYZ. Now you have to be more careful shifting. Decipher the following keyed Caesar cipher: Uwtaofq ifoo xyryfd lx krog xtocfd (Problem well stated is half solved) 5 Transposition ciphers Recall that substitution ciphers are ones in which each letter is replaced by another letter (or symbol) in some systematic way. However, the order in which the letters appear stays the same. In transposition ciphers, the letters stay the same, but the order is all mixed up. 5
One of the oldest ways to do this was created by the ancient Egyptians and Greeks. It uses a stick called scytale. The Spartans used this rather extensively - all the generals had same diameter sticks. It is easy to crack: steal a general s scytale or just try different ones. Better yet - we can crack it using math! As it ends up, the scytale is just a very old version of a greater class of ciphers called matrix transposition ciphers. Pick a matrix of a fixed size, write your message across the rows. Then read down the columns instead. Here s a simple example Troops heading west need water ): T R O O P S H E A D I N G W E S T N E E D W A T E R So the ciphertext is TEEWRASAODTTOINEPNERSGEHWD. How to crack it: Count how many letters are in the ciphertext (in this example it s 26) Make all of the matrices that would fit such a length (here it is 2x13, 3x9, 4x7, 5x6). Use two of each size - one vertical and one horizontal. Now it s trial and error. For each size matrix, write out the ciphertext across the columns. See if you can find anything legible, reading across the rows. Challenge 3. Use matrix method to decipher the following: Mowpatoeintplnndlshlleawlseebwshiaafutky (Millions saw the apple fall, but Newton asked why.) Extra activity 3 (Columnar transposition). As above in transpositions cipher, the message is written out in rows of a fixed length (use extra random letters in the end if need be) and then read out again column by column, but this time the columns are chosen in some scrambled order. So, say your keyword is CIPHER. The permutations of columns is defined by the alphabetical order of the letters in the keyword. In this case, the order would be 1 4 5 3 2 6, so you read first column first, then 5th column, then 4th and so on. To decipher it, the recipient has to work out the column lengths by dividing the message length by the key length. Then he can write the message out in columns again, then re-order the columns by reforming the key 6
word. Try to make a message to see how it works. Then decipher the following that used keyword CIPHER: Peslteeclnveteieaitmtrdtalalbyrrrlcyuayeleaehvs (Parallel lines actually meet, but they are very discrete.) Questions for thought: How can we make it harder still? Use Double Transposition - two applications of columnar transposition to a message. The two applications may use the same key for each of the two steps, or they may use different keys. It s harder to break, but possible if attacker intercepted two or more messages of the same length using the same key. During World War I, the German military used a double columnar transposition cipher, changing the keys infrequently. The system was regularly solved by the French, naming it Ubchi, who were typically able to quickly find the keys once they d intercepted a number of messages of the same length, which generally took only a few days. However, the French success became widely-known, and the Germans changed to a new system on 18 November 1914. During World War II, the double transposition cipher was used by Dutch Resistance groups, the French Maquis and the British Special Operations Executive (SOE). It was also used by agents of the American Office of Strategic Services and as an emergency cipher for the German Army and Navy. Until the invention of the VIC cipher, double transposition was generally regarded as the most complicated cipher that an agent could operate reliably under difficult field conditions. 7