{"id":380,"date":"2003-03-26T13:23:36","date_gmt":"2003-03-26T17:23:36","guid":{"rendered":"\/?p=380"},"modified":"2007-03-17T10:49:52","modified_gmt":"2007-03-17T14:49:52","slug":"cryptography-a-brief-history-part-i","status":"publish","type":"post","link":"https:\/\/www.godofthemachine.com\/?p=380","title":{"rendered":"Cryptography: A Brief History, Part I"},"content":{"rendered":"<p>In the beginning were transposition and substitution. Transposition ciphers, which date back to at least the fifth century B.C., are giant anagrams. You scramble all the letters according to an agreed-upon pattern and put them back together the same way. A grade-school example is the rail-fence. Extract the odd-numbered characters from a message, write them in sequence, and follow them by the even-numbered characters, so<\/p>\n<p align=\"center\">S H U F F L E O F F T H I S M O R T A L C O I L<\/p>\n<p>becomes<\/p>\n<p align=\"center\">S U F E F T I M R A C I H F L O F H S O T L O L<\/p>\n<p>Another transposition cipher, beloved of the Spartans, is the <a href=\"http:\/\/www.jura.ch\/lcp\/cours\/dm\/codage\/transpo\/scytale.html\">scytale<\/a>, which is a wooden staff of a certain diameter. Wind a ribbon of leather or parchment around it, and write your message on it. Unwrap the ribbon, and voil\u00c3\u00a0, your message is scrambled, awaiting delivery to someone with another wooden stick of precisely the same diameter. A scytale, if it&#8217;s of a fixed diameter, is just another version of the rail-fence cipher. If it isn&#8217;t fixed, then you&#8217;ve bought yourself a major hardware distribution problem. <\/p>\n<p>Substitution ciphers are sometimes called Caesar ciphers after Julius Caesar, who didn&#8217;t invent them but employed them frequently. If you&#8217;ve ever seen <a href=\"http:\/\/www.pbs.org\/wgbh\/nova\/teachers\/activities\/2615_decoding_03.html\">a decoder ring<\/a> from a cereal box you know what a Caesar cipher is. Take the alphabet and shift it three places. A becomes D, Q becomes T, Y goes around the bend and becomes B, and there you have it. Obviously if you restrict yourself to a simple shift you have only 25 distinct ciphers. (A <b>cipher<\/b> is a code in which each symbol stands for a single letter of the alphabet.) But if you allow any rearrangement of the alphabet, then you have 25<sup>25<\/sup> unique ciphers, which is a lot.<\/p>\n<p>This enormous number of ciphers to choose from makes substitution an advance over transposition. Once you know you&#8217;re dealing with a transposition cipher you&#8217;re halfway home, because there are only so many plausible ways to transpose letters. A transposition cipher, in other words, depends on the secrecy of the algorithm. But with a substitution cipher, even if you know that&#8217;s what it is, you need to discover the precise letter mapping, and there are far, far too many to try them all. A substitution cipher depends on the secrecy of the key, and it&#8217;s a helluva lot easier to change the key than it is to change the algorithm. The first principle of cryptography, laid down by <a href=\"http:\/\/www.ciphersbyritter.com\/GLOSSARY.HTM#KerckhoffsRequirements\">Kerckhoff<\/a> in 1883, is that any cipher that relies on the secrecy of the algorithm, as opposed to the key, is inherently insecure, because, sooner or later, someone will steal your scytale, or your Enigma machine. To this day you will see supposed security experts touting their new, proprietary, double-secret algorithms, which is an infallible sign of snake oil. &#8220;Security by obscurity&#8221; is the derisory term among cryptanalysts. <\/p>\n<p>A few Arab scientists finally got wise to substitution ciphers around the ninth century AD. They began with the simple observation that some letters are a lot more common than others. And not only letters, but digrams and trigrams, sequences of two and three letters. Once you realize that 13% of the letters in ordinary English prose are E&#8217;s, 10% are T&#8217;s and 8% are A&#8217;s, and that three consecutive vowels or consonants are pretty rare, breaking substitution ciphers becomes straightforward. A decent armchair cryptanalyst, given enough ciphertext, can usually crack a simple substitution cipher in about ten minutes. Here&#8217;s <a href=\"http:\/\/www.santacruzpl.org\/readyref\/files\/g-l\/ltfrqeng.shtml\">the letter frequency table<\/a> in English, along with a list of the commonest digrams and trigrams. (Scrabble follows the table fairly accurately, although not exactly, since in Scrabble it matters only how many words contain a given letter, not how common it is. The highest scoring letter relative to its frequency is H, which scores 4 despite being the 9th most common letter in the alphabet, its frequency being largely due to the definite article. The lowest is U, which scores 1 despite being 15th.)<\/p>\n<p>Code makers tried many ruses to foil frequency analysis. Null symbols, which represent no letter at all, were added. More insidious were operation symbols, which represented not a letter but an instruction, such as &#8220;delete the previous letter.&#8221; Since one of the standard techniques to break a substitution cipher is to look for common words like &#8220;and&#8221; and &#8220;the,&#8221; special symbols were substituted for them. Messages were deliberately spelled badly, with, say, k&#8217;s for c&#8217;s. The best code breakers defeated all of these techniques. <\/p>\n<p>The code makers needed a breakthrough, and it was supplied by Blaise de Vigen\u00c3\u00a8re. around 1550. Vigen\u00c3\u00a8re realized that the fundamental weakness of substitution ciphers is consistency: the same symbol in the ciphertext always maps to the same letter in the plaintext. He proceeded to invent the first polyalphabetic cipher. (This is incorrect; see the update below.) You begin with what&#8217;s called a Vigen\u00c3\u00a8re square:<\/p>\n<p align=\"center\"><img decoding=\"async\" src=\"\/\/www.godofthemachine.com\/images\/vigenere.gif\" alt=\"A Vigen\u00c3\u00a8re Square\"\/> <\/p>\n<p>Reading across the table, you see a simple series of Caesar ciphers: A is unshifted, B is shifted one letter, and so forth. Now you choose a code word; this is the key. So suppose we want to encrypt SHUFFLE OFF THIS MORTAL COIL with the keyword HAMLET. You begin by repeating the keyword to the length of the message. Our message has 24 letters, so we have HAMLETHAMLETHAMLETHAMLET. Now you encrypt the first letter, S, using the H row of the Vigen\u00c3\u00a8re square, so it becomes a Z. The next letter, H, is encrypted with the A row, which is unshifted, so it remains an H. The U is encrypted with the M row, becoming a G. And so forth. The encrypted message reads:<\/p>\n<p align=\"center\">Z H G Q J E L O R Q X A P S Y Z V M H L O Z M E<\/p>\n<p>You can try it yourself <a href=\"http:\/\/www.perse.co.uk\/Fun\/CodeApplet\/VigenereCipher.htm\">here<\/a>. <\/p>\n<p>In the Vigen\u00c3\u00a8re square the key is very small, just a single word, which vastly simplified the distribution problem. Modified substitution ciphers had grown so large that passing around complex codebooks was required. But its principal advantage is that it stymies basic frequency analysis, because one-to-one mapping between plaintext and ciphertext symbols no longer holds. In our message, for example, Z appears three times, representing two different letters, S and O. M appears twice, representing H and I. Conversely, the plaintext F is represented by Q, J, and R. The result is so nasty to analyze that Vigen\u00c3\u00a8re&#8217;s cipher was nicknamed <em>le chiffre indechiffrable<\/em>, with considerable justice. It remained unbroken for 300 years, and it took a genius to do it.<\/p>\n<p>In <a href=\"http:\/\/www.godofthemachine.com\/?p=380\">Part II<\/a> we&#8217;ll break the Vigen\u00c3\u00a8re cipher, defeat the Nazis, and complete this little history.<\/p>\n<p>(<b>Update:<\/b> Actually it was Leon Alberti, in 1466, who first proposed polyalphabetic substitution. The &#8220;Vigen\u00c3\u00a8re&#8221; square first appears in Trithemius, in 1499, and Belaso, in 1553, added the repeating keyword. Vigen\u00c3\u00a8re himself synthesized these results in 1585. Thanks to <a href=\"http:\/\/www.acdouglas.com\">AC Douglas<\/a> for pointing some of this out.) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the beginning were transposition and substitution. Transposition ciphers, which date back to at least the fifth century B.C., are giant anagrams. You scramble all the letters according to an agreed-upon pattern and put them back together the same way. A grade-school example is the rail-fence. Extract the odd-numbered characters from a message, write them <a href='https:\/\/www.godofthemachine.com\/?p=380' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-380","post","type-post","status-publish","format-standard","hentry","category-code","category-5-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=\/wp\/v2\/posts\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380"}],"version-history":[{"count":0,"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.godofthemachine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}