{VERSION 5 0 "SGI MIPS UNIX" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 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 Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 3 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading 1" 0 3 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }1 0 0 0 8 4 0 0 0 0 0 0 -1 0 } {PSTYLE "Warning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Diagnostic" 7 9 1 {CSTYLE "" -1 -1 "" 0 1 64 128 64 1 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 " " 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }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 1 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 256 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 3 "" 0 "" {TEXT -1 58 "Maple Summer Workshop 2004 : Programming in Maple Tutorial." }}}{EXCHG {PARA 0 "" 0 "" {TEXT 260 26 "RSA Public Key Encryption." }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "Michael Monagan, June 2004." }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 256 "" 0 "" {TEXT -1 124 "These Maple programs \+ illustrate strings in Maple, tables, and modular arithmetic. Then we make the routines into a module." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 87 "Here \+ is a string, the letters in the alphabet that we'll use for encryption /decryption." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 71 "alphabet := \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .,!\";" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%)alphabetGQYABCDEFGHIJKLMNOPQRSTUVWX YZabcdefghijklmnopqrstuvwxyz~.,!6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "length(alphabet);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# \"#c" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "Here are the operations o n strings that we will use. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "alphabet[2];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q\"B6\"" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "alphabet[2..3];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q#BC6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "cat(\"I'm\", \" \", \"hungry\", \"!\");" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q,I'm~hungry!6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 36 "Now encoding the letters as integers" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "for i to length(alphabet) do\n l := alphabet[i]; C ode[l] := i; Letter[i] := l \nod:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "Letter[2];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q\"B6\" " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "Code[\"B\"];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 54 "The alphabet does include a space in position 53 note." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "Code[\" \"];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#`" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 250 "Now here \+ is the encryption function for encrypting a message. We convert the s tring to a list of single letters (one must to encrypt this way but th is is for illustration). Then we encrypt the codes one at a time usi ng the RSA encryption exponent " }{TEXT 256 1 "e" }{TEXT -1 13 " and m odulus " }{TEXT 257 1 "n" }{TEXT -1 63 ". Decryption is the reverse u sing the RSA decryption exponent " }{TEXT 258 1 "d" }{TEXT -1 13 " and modulus " }{TEXT 259 1 "n" }{TEXT -1 64 ", and then converting the co des back to the letters and message." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 242 "encrypt := proc(message,e,n) local letters,codes,cyp hertext,i,x;\n letters := [seq(message[i],i=1..length(message))];\n codes := [seq( Code[letters[i]], i=1..length(message) )];\n cyp hertext := [seq( x &^ e mod n, x = codes )];\n end:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 217 "decrypt := proc(cyphertext,d,n)\nl ocal codes, letters, y, i, message;\n codes := [seq( y &^ d mod n, \+ y = cyphertext )];\n letters := [seq( Letter[codes[i]], i=1..nops(c odes) )];\n message := cat(op(letters))\nend:" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 219 "In RSA, one finds two (large) primes, p and q, co mputes their product n, and pubishes n together with e as the public k ey. A user converts a message into a sequence of numbers and encodes \+ a number x using the function." }}}{EXCHG {PARA 11 "" 1 "" {XPPMATH 20 "6#/%\"mG-%$modG6$)%\"xG%\"eG%\"nG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "p := 101; q := 103; n := p*q; e := 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"pG\"$,\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"qG\"$.\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"&./\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"eG\"\"(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "message := \"hello\";\n" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%(messageGQ&hello6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "trace(encrypt);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%(encryptG" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "encoding := encrypt(message, e,n);" }}{PARA 9 "" 1 "" {TEXT -1 44 "\{--> enter encrypt, args = \"he llo\", 7, 10403" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%(lettersG7'Q\"h6 \"Q\"eF'Q\"lF'F)Q\"oF'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%&codesG7' \"#M\"#J\"#QF(\"#T" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%+cyphertextG7' \"%\\v\"%r!)\"%%)encodingG7'\"%\\v\"%r!)\"% " 0 "" {MPLTEXT 1 0 23 "igcd( e, (p-1)*(q-1) );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\" " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 101 "We now calculate the secret \+ decryption key which the user keeps secret, along with the primes p & \+ q. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "d := 1/e mod (p-1)*( q-1);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"dG\"%V()" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "e*d mod (p-1)*(q-1);" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "trace(decrypt);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%(decryptG" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "decrypt( encoding, d, n ); " }}{PARA 9 "" 1 "" {TEXT -1 70 "\{--> enter decrypt, args = [7549, 80 71, 7617, 7617, 2165], 8743, 10403" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# >%&codesG7'\"#M\"#J\"#QF(\"#T" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%(le ttersG7'Q\"h6\"Q\"eF'Q\"lF'F)Q\"oF'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #>%(messageGQ&hello6\"" }}{PARA 9 "" 1 "" {TEXT -1 46 "<-- exit decryp t (now at top level) = \"hello\"\}" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# Q&hello6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 385 "We remark that today, one can factor one hundred digit n umbers. It is considered safe if the primes are both of the order of \+ one hundred digits. So n is two hundred digits long. No known factor ization algorithms would be able to factor a two hundred digit number \+ in a reasonable length of time. Now we redo this encrypting a bock of 10 letters at a time using a 20 digits modulus.\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "p := nextprime(8113120951);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"pG\"+j578\")" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "q := nextprime(4766101972);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG\"+\")>5mZ" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "n := p*q;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"5.e7d/Pizm Q" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "e := 34781001071047370 39;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"eG\"4Rqt/r5+\"yM" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "d := 1/e mod (p-1)*(q-1);" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"dG\"5fxSa8eHqeI" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 545 "encrypt := proc(message,e,n,BL) \nlocal \+ letters,codes,cyphertext,i,x,N,block,q,blocks,r;\n letters := [seq( message[i],i=1..length(message))];\n N := length(alphabet)+1;\n \+ codes := [seq( Code[letters[i]], i=1..length(message) )];\n block : = L -> add(L[i]*N^(i-1),i=1..BL);\n q := iquo(nops(codes),BL,'r'); \n if r>0 then # pad with BL-r blanks \n codes := [op(codes), Code[\" \"]$(BL-r)]; \n q := q+1 \n fi;\n blocks := [seq( \+ block(codes[5*(i-1)+1..BL*i]), i=1..q )];\n cyphertext := [seq( x & ^ e mod n, x = blocks )];\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "trace(encrypt);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%(encryptG " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "cyphertext := encrypt(m essage,e,n,5);" }}{PARA 9 "" 1 "" {TEXT -1 148 "\{--> enter encrypt, a rgs = \"This is the day that the Lord has made, let us rejoice and be \+ glad in it!\", 3478100107104737039, 38667962370457125803, 5" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%(lettersG7eoQ\"T6\"Q\"hF'Q\"iF'Q\"sF'Q\"~F 'F)F*F+Q\"tF'F(Q\"eF'F+Q\"dF'Q\"aF'Q\"yF'F+F,F(F/F,F+F,F(F-F+Q\"LF'Q\" oF'Q\"rF'F.F+F(F/F*F+Q\"mF'F/F.F-Q\",F'F+Q\"lF'F-F,F+Q\"uF'F*F+F3F-Q\" jF'F2F)Q\"cF'F-F+F/Q\"nF'F.F+Q\"bF'F-F+Q\"gF'F6F/F.F+F)F:F+F)F,Q\"!F' " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"NG\"#d" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&codesG7eo\"#?\"#M\"#N\"#X\"#`F(F)F*\"#YF'\"#JF*\"#I \"#F\"#^F*F+F'F.F+F*F+F'F,F*\"#7\"#T\"#WF-F*F'F.F)F*\"#RF.F-F,\"#bF*\" #QF,F+F*\"#ZF)F*F2F,\"#OF1F(\"#HF,F*F.\"#SF-F*\"#GF,F*\"#LF5F.F-F*F(F9 F*F(F+\"#c" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%&blockGf*6#%\"LG6\"6$% )operatorG%&arrowGF(-%$addG6$*&&9$6#T#\"\"\")T%,&F3F4F4!\"\"F4/F3;F4T( F(F(6(%\"iG%\"iG%\"NG%\"NG%#BLG\"\"&" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#>%\"qG\"#9" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&codesG7go\"#?\"#M\" #N\"#X\"#`F(F)F*\"#YF'\"#JF*\"#I\"#F\"#^F*F+F'F.F+F*F+F'F,F*\"#7\"#T\" #WF-F*F'F.F)F*\"#RF.F-F,\"#bF*\"#QF,F+F*\"#ZF)F*F2F,\"#OF1F(\"#HF,F*F. \"#SF-F*\"#GF,F*\"#LF5F.F-F*F(F9F*F(F+\"#cF*F*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG\"#:" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%'blocks G71\"*6u\"zc\"*4xfn$\"*%ycMa\"*)R*o!\\\"*x@Kl&\"*[\"p^c\"*Yqk@%\"*Chvp &\"*N&)41&\"*TI!fQ\"*$H0`c\"*MI[0$\"*I'f@H\"*RD*pc\"*$)yYp&" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%+cyphertextG71\"5#z$3)*pLU&)eB\"5$>kjw)em6 @E\"5@%o.!R!H9$RM\"5-R=+eWh;XH\"41M)pXnbW)3$\"5L;5]br@Ks6u-A3 f<#\"5np)3%\"5yEsI%))y9$QH" }}{PARA 9 "" 1 "" {TEXT -1 364 "<-- exit encrypt (now at top level) = [23588542336998083 792, 26211166588766364193, 34393142903900368421, 29451661445800183902, 3088445567456983406, 30173221715550101633, 904702970657550349, 749606 6263237920885, 33105995165352940200, 28480548095442776300, 28592811248 612964322, 21759082202741172198, 17203281846622707917, 408869671991235 6136, 29383147888430722678]\}" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%+cy phertextG71\"5#z$3)*pLU&)eB\"5$>kjw)em6@E\"5@%o.!R!H9$RM\"5-R=+eWh;XH \"41M)pXnbW)3$\"5L;5]br@Ks6u-A3f<#\"5np) 3%\"5yEsI%))y9$QH" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 167 "Here is a r outine to convert an integer to an integer in base B, N digits base B. The example shows the number 00012345 base 100 being converted to 5 \+ base 100 digits." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 111 "base : = proc(a,B,N) local L,b;\n b := a;\n L := NULL; to N do L \+ := L,irem(b,B,'b') od; [L];\n end: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "base(12345,100,4);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #7&\"#X\"#B\"\"\"\"\"!" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 305 " decrypt := proc(cyphertext,d,n,BL)\nlocal blocks,codes,letters,message ;\n blocks := [seq( x &^ d mod n, x = cyphertext )];\n blocks := map(base,blocks,1+length(alphabet),BL);\n codes := map(op,blocks); \n letters := [seq( Letter[codes[i]], i=1..nops(codes) )];\n mes sage := cat(op(letters));\nend: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "trace(decrypt);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%( decryptG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "decrypt(cyphert ext,d,n,5);" }}{PARA 9 "" 1 "" {TEXT -1 399 "\{--> enter decrypt, args = [23588542336998083792, 26211166588766364193, 34393142903900368421, \+ 29451661445800183902, 3088445567456983406, 30173221715550101633, 90470 2970657550349, 7496066263237920885, 33105995165352940200, 284805480954 42776300, 28592811248612964322, 21759082202741172198, 1720328184662270 7917, 4088696719912356136, 29383147888430722678], 30587029581354407759 , 38667962370457125803, 5" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%'blocks G71\"*6u\"zc\"*4xfn$\"*%ycMa\"*)R*o!\\\"*x@Kl&\"*[\"p^c\"*Yqk@%\"*Chvp &\"*N&)41&\"*TI!fQ\"*$H0`c\"*MI[0$\"*I'f@H\"*RD*pc\"*$)yYp&" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%'blocksG717'\"#?\"#M\"#N\"#X\"#`7'F)F*F+\" #YF(7'\"#JF+\"#I\"#F\"#^7'F+F-F(F1F-7'F+F-F(F/F+7'\"#7\"#T\"#WF0F+7'F( F1F*F+\"#R7'F1F0F/\"#bF+7'\"#QF/F-F+\"#Z7'F*F+F8F/\"#O7'F7F)\"#HF/F+7' F1\"#SF0F+\"#G7'F/F+\"#LF>F17'F0F+F)FEF+7'F)F-\"#cF+F+" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&codesG7go\"#?\"#M\"#N\"#X\"#`F(F)F*\"#YF'\"#JF* \"#I\"#F\"#^F*F+F'F.F+F*F+F'F,F*\"#7\"#T\"#WF-F*F'F.F)F*\"#RF.F-F,\"#b F*\"#QF,F+F*\"#ZF)F*F2F,\"#OF1F(\"#HF,F*F.\"#SF-F*\"#GF,F*\"#LF5F.F-F* F(F9F*F(F+\"#cF*F*" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%(lettersG7goQ \"T6\"Q\"hF'Q\"iF'Q\"sF'Q\"~F'F)F*F+Q\"tF'F(Q\"eF'F+Q\"dF'Q\"aF'Q\"yF' F+F,F(F/F,F+F,F(F-F+Q\"LF'Q\"oF'Q\"rF'F.F+F(F/F*F+Q\"mF'F/F.F-Q\",F'F+ Q\"lF'F-F,F+Q\"uF'F*F+F3F-Q\"jF'F2F)Q\"cF'F-F+F/Q\"nF'F.F+Q\"bF'F-F+Q \"gF'F6F/F.F+F)F:F+F)F,Q\"!F'F+F+" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#> %(messageGQfoThis~is~the~day~that~the~Lord~has~made,~let~us~rejoice~an d~be~glad~in~it!~~6\"" }}{PARA 9 "" 1 "" {TEXT -1 116 "<-- exit decryp t (now at top level) = \"This is the day that the Lord has made, let u s rejoice and be glad in it! \"\}" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# QfoThis~is~the~day~that~the~Lord~has~made,~let~us~rejoice~and~be~glad~ in~it!~~6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 1351 "RSA := mod ule()\n export encrypt, decrypt;\n local UnBlock,alphabet,Code,Let ter,N,i,l,BlockLength;\n\nalphabet := \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcd efghijklmnopqrstuvwxyz .,!\";\nN := length(alphabet);\nfor i to N do l := alphabet[i]; Code[l] := i; Letter[i] := l; od;\nN := N+1;\n\nBlock Length := proc(n) local B; for B from 1 while N^B < n do od; B-1 end; \nUnBlock := proc(a,B) local L,b;\n b := a;\n L := NULL; t o B do L := L,irem(b,N,'b') od; [L];\nend;\n\nencrypt := proc(message, e,n) \nlocal letters,codes,cyphertext,i,x,block,q,blocks,r,BL;\n BL := BlockLength(n);\n letters := [seq(message[i],i=1..length(messag e))];\n codes := [seq( Code[letters[i]], i=1..length(message) )];\n block := proc(L) local i; add(L[i]*N^(i-1),i=1..BL) end;\n q := iquo(nops(codes),BL,'r');\n if r>0 then # pad with BL-r blanks \n \+ codes := [op(codes),Code[\" \"]$(BL-r)]; \n q := q+1 \n \+ fi;\n blocks := [seq( block(codes[BL*(i-1)+1..BL*i]), i=1..q )];\n cyphertext := [seq( x &^ e mod n, x = blocks )];\nend:\n\ndecrypt \+ := proc(cyphertext,d,n)\nlocal blocks,codes,letters,message,BL;\n B L := BlockLength(n);\n blocks := [seq( x &^ d mod n, x = cyphertext )];\n blocks := map(UnBlock,blocks,BL);\n codes := map(op,block s);\n letters := [seq( Letter[codes[i]], i=1..nops(codes) )];\n \+ message := cat(op(letters));\nend:\n\nend module;\n " }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%$RSAG`6$%(encryptG%(decryptGb6#%+thismoduleG6 *%(UnBlockG%)alphabetG%%CodeG%'LetterG%\"NG%\"iG%\"lG%,BlockLengthG6\" 6$%(encryptG%(decryptGF5F5F5F56\"6*%(UnBlockG%)alphabetG%%CodeG%'Lette rG%\"NG%\"iG%\"lG%,BlockLengthG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "p,q,n,e,d;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6'\"+j578\")\"+\") >5mZ\"5.e7d/PizmQ\"4Rqt/r5+\"yM\"5fxSa8eHqeI" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "message;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#QdoTh is~is~the~day~that~the~Lord~has~made,~let~us~rejoice~and~be~glad~in~it !6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "cyphertext := RSA:- encrypt(message,e,n);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%+cyphertext G7)\"4&HP$)e-&*\"5X&z\"G?z(4;?$\"5lF@%HL9@Fd#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "RSA:-decrypt(cyphertext,d,n);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#QhoThis~is~the~day~that~the~Lord~has~made,~let~us~rejoi ce~and~be~glad~in~it!~~~~6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "4 0 0" 17 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 } {PAGENUMBERS 0 1 2 33 1 1 }