{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 1 12 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 2 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 2 0 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "G eneva" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "Heading 3" -1 5 1 {CSTYLE "" -1 -1 "Geneva" 1 12 0 0 0 1 1 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 11 12 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "T itle" -1 18 1 {CSTYLE "" -1 -1 "Geneva" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Author" -1 19 1 {CSTYLE "" -1 -1 "Geneva" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 256 1 {CSTYLE "" -1 -1 "Geneva" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 4 4 1 0 1 0 2 2 0 1 }{PSTYLE " Heading 3" -1 257 1 {CSTYLE "" -1 -1 "Geneva" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 258 1 {CSTYLE "" -1 -1 "Geneva" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 4 4 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 14 "Caesar Codes 2" }}{PARA 256 "" 0 "" {TEXT -1 22 "Monoalphabetic ciphers" }}{PARA 19 "" 0 "" {TEXT -1 22 "\251Mike May, S. J., 2002" }}{PARA 0 "" 0 "" {TEXT 256 30 "(Worksheet 2 for Cryptography)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "As al ways, we start by having our standard message ready." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 170 "message1 :=\"AZaz Good morning Mr. Phelp s. Your mission for today, \nshould you choose to accept it, is to en code this message. AZaz\";\ntemp[1] := convert(message1, bytes);" }} {PARA 12 "" 1 "" {XPPMATH 20 "6#>%)message1GQbrAZaz~Good~morning~Mr.~P helps.~~Your~mission~for~today,~|+should~you~choose~to~accept~it,~is~t o~encode~this~message.~AZaz6\"" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>&%% tempG6#\"\"\"7cr\"#l\"#!*\"#(*\"$A\"\"#K\"#r\"$6\"F/\"$+\"F-\"$4\"F/\" $9\"\"$5\"\"$0\"F3\"$.\"F-\"#xF2\"#YF-\"#!)\"$/\"\"$,\"\"$3\"\"$7\"\"$ :\"F7F-F-\"#*)F/\"$<\"F2F-F1F4F=F=F4F/F3F-\"$-\"F/F2F-\"$;\"F/F0F+\"$@ \"\"#WF-\"#5F=F9F/F?F;F0F-FBF/F?F-\"#**F9F/F/F=F:F-FAF/F-F+FEFEF:F " 0 "" {MPLTEXT 1 0 1011 "caesarb := proc(letter, key)\n#This procedure chang es one letter with a ceasar code\n local temp, temp2;\n temp : = letter:\n if temp > 64 then\n if temp < 91 then\n tem p := 65 + ((temp - 65 + key) mod 26):\n fi:fi:\n if temp > 96 th en\n if temp < 123 then\n temp := 97 + ((temp - 97 + key) mod 26):\n fi:fi:\n temp:\n end:\nencodecaesarb := proc(messag e, key)\n#This procedure uses ceasarb to uncode a string\n local t emp:\n #first convert the message to numerical equivalents\n t emp[1] := convert(message, bytes):\n #then add the key to each le tter to scrable the letters\n temp[2] := map(caesarb, temp[1], key) :\n #then convert back to the ASCII code\n convert(temp[2], by tes);\n end:\nbreakcaesarb := proc(message)\n#This procedure uses enc odeceasarb to try all the keys on a given message.\n local temp, k ey;\n for key from 1 to 25 do\n temp := encodecaesarb(message, \+ - key):\n print(`The key of `||key,` produces - `,temp);\n o d;\n end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 288 "We would like to \+ modify them so that we can use another monoalphabetic cipher rather th an the simple Caesar cipher. To do that we would like the addition of the key mod 26 to be pulled out into a separate procedure. We first \+ give the procedure that we would feed the whole message into." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 766 "monoalph := proc(letter, ru le, key)\n#This procedure changes one letter with a monoalphabetic cip her named rule\n local temp, temp2;\n temp := letter:\n if l etter > 64 then\n if letter < 91 then\n temp := 65 + rule (temp - 65, key):\n fi:fi:\n if letter > 96 then\n if lette r < 123 then\n temp := 97 + rule(temp - 97, key):\n fi:fi: \n temp:\n end:\nencodemonoalph := proc(message, rule, key)\n#This \+ procedure uses monoalph to uncode a string\n local temp:\n #f irst convert the message to numerical equivalents\n temp[1] := conv ert(message, bytes):\n #then uses monalph to scrable the letters \n temp[2] := map(monoalph, temp[1], rule, key):\n #then conve rt back to the ASCII code\n convert(temp[2], bytes):\n end:" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 47 "Now we produce the rule for the Ca esar cipher. " }}{PARA 0 "" 0 "" {TEXT -1 81 "(In producing our coding rules we send a to 0, b to 1, and so on, up to z to 25.)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 111 "caesarrule := (letter, key) -> ((l etter + key) mod 26):\n#This procedure is the rule used for the Caesar cipher." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 82 "The test of the code \+ is obviously that it correctly encodes and decodes a message." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 103 "mess[1] := encodemonoalph(m essage1, caesarrule, 5);\nmess[2] := encodemonoalph(mess[1], caesarrul e, -5);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>&%%messG6#\"\"\"QbrFEfe~Lt ti~rtwsnsl~Rw.~Umjqux.~~Dtzw~rnxxnts~ktw~ytifd,~|+xmtzqi~dtz~hmttxj~yt ~fhhjuy~ny,~nx~yt~jshtij~ymnx~rjxxflj.~FEfe6\"" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>&%%messG6#\"\"#QbrAZaz~Good~morning~Mr.~Phelps.~~Your~ mission~for~today,~|+should~you~choose~to~accept~it,~is~to~encode~this ~message.~AZaz6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 69 "Notice that \+ if the encoding key is 5 we can use -5 as a decoding key." }}}{SECT 0 {PARA 5 "" 0 "" {TEXT -1 0 "" }{TEXT 257 9 "Exercise:" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 199 "1) Type in the first line of your favorite po em as message2. Use the modified coded to encode it with your favorit e key, saving the result as message3. Decode message3 to verify the p rocess works." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}} {SECT 0 {PARA 258 "" 0 "" {TEXT -1 30 "General monoalphabetic ciphers " }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 307 "The advantage of the modified approach is that we can set a new cipher by defining a new coding rul e. One of the simplest rules is one that permutes the letters. The k ey is then a vector of length 26 whose entries are the numbers from 0 \+ through 25 in some order. Rules of this sort permute the 26 letters" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "permutationRule := (lette r, key) -> key[letter+1];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%0permut ationRuleGf*6$%'letterG%$keyG6\"6$%)operatorG%&arrowGF)&9%6#,&9$\"\"\" F2F2F)F)F)" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 153 "Consider the follo wing key which causes the permutationRule to switch pairs of letters. \+ (A goes to B and B goes to A, C goes to D and D goes to C, etc.)" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 141 "pairkey := \n[1,0,3,2,5,4,7 ,6,9,8,11,10,13,12,15,14,17,16,19,18,21,20,23,22,25,24];\ncode1 := enc odemonoalph(message1,permutationRule,pairkey);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%(pairkeyG7<\"\"\"\"\"!\"\"$\"\"#\"\"&\"\"%\"\"(\"\"' \"\"*\"\")\"#6\"#5\"#8\"#7\"#:\"#9\"#<\"#;\"#>\"#=\"#@\"#?\"#B\"#A\"#D \"#C" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&code1GQbrBYby~Hppc~npqmjmh~ Nq.~Ogfkot.~~Zpvq~njttjpm~epq~spcbz,~|+tgpvkc~zpv~dgpptf~sp~bddfos~js, ~jt~sp~fmdpcf~sgjt~nfttbhf.~BYby6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 81 "This key has the feature that the key to encode is the same as \+ the key to decode." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "code2 := encodemonoalph(code1, permutationRule, pairkey);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&code2GQbrAZaz~Good~morning~Mr.~Phelps.~~Your~miss ion~for~today,~|+should~you~choose~to~accept~it,~is~to~encode~this~mes sage.~AZaz6\"" }}}{SECT 0 {PARA 257 "" 0 "" {TEXT -1 10 "Exercises:" } }{EXCHG {PARA 0 "" 0 "" {TEXT -1 112 "2) Write a key that causes the \+ permutationRule to \"invert the letters\", i.e., take a to z, b to y, and so on. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "3) Use the inversion rule to encode mess age2. Then apply the rule again to decode the message." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 164 "4) Write a key that permutes the alphabet to the alphabet arr anged with the letters used in your name first, followed by the rest o f the alphabet in reverse order." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 51 "5) Use the k ey from exercise 4 to encode message2." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 94 "6) Produce a rule to undo the scrambling key of the previous exercise. Verify tha t it works." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 161 "7) Can all permutation rules be undone \+ by another permutations? Either produce a counterexample or explain h ow to produce the rule that undoes the permutation." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 212 "Another kind of rule we can easily think of is a multiplication rule \+ that multiplies the letters by some key mod 26. We can also produce a linear rule that multiplies by a first key and adds a second key mod \+ 26." }}}{SECT 0 {PARA 5 "" 0 "" {TEXT -1 0 "" }{TEXT 258 10 "Exercises :" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 108 "8) Produce a rule to \"mult iply letters by key\" for a key that is given as a parameter at time o f execution." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 78 "9) Apply your rule to the alphabet with \+ key taking the values of 3, 5, and 7," }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "10) Give the key values that undo the multiplicative rule for 3, 5, and 7." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 116 "11) What multiplicative keys cannot be undone? Give an example of what happens if we try to use one of these keys." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 244 "12) Produce a rule to \"multiply letters by the first k ey, then adds the second key\" with the two keys given as parameters a t the time of execution. Show that your rule works with a nontrivial \+ key, and that is then undone by using another key." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 69 "13) Explain how to produce the key to undo in the previous exercise." }} }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "0 0 0" 0 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }