{VERSION 6 0 "IBM INTEL LINUX" "6.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 }{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 "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 "Title" 0 18 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 1 0 0 0 0 0 0 1 }3 0 0 -1 12 12 0 0 0 0 0 0 19 0 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 23 "Encryption & Decryption" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 155 "To encrypt a message we need a method of turning a string of text into a number. We begin by orderin g the alphabetic and the other key-board symbols, with " }{XPPEDIT 18 0 "a;" "6#%\"aG" }{TEXT -1 13 " followed by " }{XPPEDIT 18 0 "b;" "6#% \"bG" }{TEXT -1 2 ", " }{XPPEDIT 18 0 "b;" "6#%\"bG" }{TEXT -1 4 " by \+ " }{XPPEDIT 18 0 "c;" "6#%\"cG" }{TEXT -1 6 ", etc:" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 151 "`crypt/a lphabet` := \n `abcdefghijklmnopqrstuvwxyz`\n ||`ABCDEFGHIJKLMNOPQ RSTUVWXYZ`\n ||```1234567890-=~!@#$%^&*()_+`\n ||` ,./<>?;':\"[]\{ \}| `:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 268 "The symbols || me ans concatenate in Maple Version 6 and later versions. I am endebted t o Professor John Cosgrave for the following function (and its inverse ) that turns a string of text into a number. (See Professor Cosgrave's home page at: www.spd.dcu.ie/johnbcos/.)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 251 "to_number := proc(s t, string) \nlocal ll, nn, ss, ii; \nll := length(st);\nif ll = 0 the n RETURN(0) fi; \nnn := 1;\nfor ii to ll do \nss := SearchText(substri ng(st, ii .. ii),\n `crypt/alphabet`);\nnn := 100*nn + ss \nod;\nnn - 10^(2*ll) \nend:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 85 "Next we do some examples, where the text needs to be included w ithin backward quotes." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "N:=to_number(`I came I saw I conque red.`);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"NG\"S\"[]!=0@<9:.zNzB,> zNz08,.zN" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 191 "The initial 35 represents the letter `I', the 79 is the blank, the 03 is the letter `c', and 81 is the period at the end. Ne xt we need a program to recover a string of text from the number." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 273 "from_number := proc(nn, int eger) \nlocal ss, mm, ll, pp, ii, ans; mm := nn;\nll := floor(1/2*trun c(evalf(log10(mm))))+1;\nans := ``; for ii to ll do mm := mm/100;\npp \+ := 100*frac(mm);\nss := substring(`crypt/alphabet`, pp..pp);\nans := c at(ss, ans); mm := trunc(mm)\nod; ans end:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "from_number(N);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%:I~came~I~saw~I~conquered.G" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 93 "It should be noted that if we use th e above function on a randomly chosen number we will get " }{TEXT 256 12 "gobbledegook" }{TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "R:=rand(10^85)();" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"RG\"`p4V(3h_WZb\"Q;*fz3r`N6Re`2sccad!>8W QWUQk?il8[2$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "from_number (%);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%KcgVm=9t-LPRLRmse(S=!t(I<]m2K j'~pLo1*Szj'QiG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "Next we generate public and private keys for our fr iends Bob and Alice who wish to communicate privately. First for Alice and then Bob." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 31 "p[a]:=nextprime(rand(10^60)());" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>&%\"pG6#%\"aG\"gnTQz\")o6xsc)*=*Rh)yS_#GfvO0*># Q3Ba-&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "q[a]:=nextprime(r and(10^70)());" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"qG6#%\"aG\"`o\" G1\\JyJ#fq%f,M+%)4XO([0()z%H;E,VR&zN$Gx!)" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 19 "n[a]:=p[a]*q[a]; # " }{XPPEDIT 18 0 "n[a];" "6#&%\" nG6#%\"aG" }{TEXT -1 23 " is public but not the " }{XPPEDIT 18 0 "p[a] ;" "6#&%\"pG6#%\"aG" }{TEXT -1 5 " and " }{XPPEDIT 18 0 "q[a];" "6#&% \"qG6#%\"aG" }{TEXT -1 1 "." }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"nG 6#%\"aG\"\\s@`,yIr%>`xP1m8&><:I[A(3At,e4W#)G[`k*[*>S_f!G\\io'oB7Su#ewi x-%\\t%HjTiw\"fS" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "length( %);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"$H\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "e[a]:=nextprime(12345678987654321);# " } {XPPEDIT 18 0 "e[a];" "6#&%\"eG6#%\"aG" }{TEXT -1 16 " is also public. " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"eG6#%\"aG\"2tVl()*ycM7" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "phi_na:=(p[a]-1)*(q[a]-1); # " }{TEXT -1 11 "This number" }{MPLTEXT 1 0 1 " " }{XPPEDIT 18 0 "phi(n [a]);" "6#-%$phiG6#&%\"nG6#%\"aG" }{TEXT -1 16 " is kept secret." }} {PARA 12 "" 1 "" {XPPMATH 20 "6#>%'phi_naG\"\\s+_J\")yT%**zW)G@>DUD)Rn 5EtoWj$**z()3`)>O79>S_f!G\\io'oB7Su#ewix-%\\t%HjTiw\"fS" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "igcd(e[a],phi_na);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "d[a]:=e[a]^(-1) mod phi_na; # " }{XPPEDIT 18 0 "d[a];" "6#&%\"dG6# %\"aG" }{TEXT -1 23 " is very, very private." }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"dG6#%\"aG\"\\sP!pM!QhAf$GfM_$pt2K)H$G=:`;Ld&e7spY^ v,7!)3i$4\"p+BJ(H-3B(HN$p!34(Q+N@y$\\AP" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "e[a]*d[a] mod phi_na;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "p[b]:=nextp rime(rand(10^58)());" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"pG6#%\"bG \"en^86.23d+TM!pxBX25a%*Gi[J\"Gtp8D[" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "q[b]:=nextprime(rand(10^68)());" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"qG6#%\"bG\"_op8)zrDv]FU&G\"f0G[K?c^U_^\"*)G*47#Hb% f9r#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "n[b]:=p[b]*q[b];" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"nG6#%\"bG\"ir>&>/NX'znVnnB&otu%* Ge\"yuca7*G))H\"Qt)[P#*z,99!)f#zAZlse=1aNcykhtA$GpK;$38" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "length(%);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"$E\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "e[ b]:=nextprime(987654321234567);" }{TEXT -1 0 "" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"eG6#%\"bG\"0(eM7Kaw)*" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 26 "phi_nb:=(p[b]-1)*(q[b]-1);" }{TEXT -1 0 "" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%'phi_nbG\"ir+oKH*Q]@*zy[b\"R+>_a2,Vmi_pQTm 1wT*G7s " 0 "" {MPLTEXT 1 0 27 "d[b]:=e[b]^(-1) mod phi_nb;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"dG6#%\"bG\"hrB23XObFxIl\">s\"\\;mLM)=B*4Ixjt\"f7P. *))pAlJL^Kqnbm%QQ<8j%o`ktaM-(pM#)34?" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 87 "Now we are ready for Bob to sen d a message to Alice. He first uses his secret exponent " }{XPPEDIT 18 0 "d[b];" "6#&%\"dG6#%\"bG" }{TEXT -1 0 "" }{TEXT -1 58 " to sign h is message before using Alice's public exponent " }{XPPEDIT 18 0 "e[a] ;" "6#&%\"eG6#%\"aG" }{TEXT -1 43 " to encrypt the message. First the \+ message " }{XPPEDIT 18 0 "M;" "6#%\"MG" }{TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 76 "M:=to_ number(`Meet me at Fog City at 8:00pm. I am madly in love with you.`); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"MG\"ar\"=_^#z3?4Bz0A:7z94zD7/, 8z8,zNz\"QhJO')='z?,zD?4Hz2:Kz?,z08z?00R" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "S:=M&^d[b] mod n[b];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"SG\"hrqxe#fAKn8/V.SWGeU!e(=VmhwqJt(Q*e!)RF$>!ou\"32.B*3@\"*fc?n HWv9HRX2Sa)*G&R*" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "C:=S&^e [a] mod n[a];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"CG\"[s$p!)f***pE* ogC)p5$pO)f)puMe=*e?\"z!*pH;;rNT^VA>Jeq)GZoIX'**y$G5Ty!)H/meW\\]bl" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "Alice receives the message " }{XPPEDIT 18 0 "C;" "6#%\"CG" } {TEXT -1 39 " from Bob and uses her secret exponent " }{XPPEDIT 18 0 " d[a];" "6#&%\"dG6#%\"aG" }{TEXT -1 156 " to decrypt. Then when she re alizes that the message does not make sense and that the message is su pposed to come from Bob, she uses Bob's public exponent " }{XPPEDIT 18 0 "e[b];" "6#&%\"eG6#%\"bG" }{TEXT -1 1 " " }{TEXT -1 24 "to retrie ve the message " }{XPPEDIT 18 0 "M;" "6#%\"MG" }{TEXT -1 1 "." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "C&^d[a] mod n[a];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"hrqxe#fAK n8/V.SWGeU!e(=VmhwqJt(Q*e!)RF$>!ou\"32.B*3@\"*fc?nHWv9HRX2Sa)*G&R*" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "%&^e[b] mod n[b];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"ar\"=_^#z3?4Bz0A:7z94zD7/,8z8,zNz\"QhJO')= 'z?,zD?4Hz2:Kz?,z08z?00R" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "from_number(%);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%fnMeet~me~at~Fog~ City~at~8:00pm.~I~am~madly~in~love~with~you.G" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 75 "So Alice is now sure t his message comes from Bob. But, will she meet him???" }}}}{MARK "3 0 \+ 0" 267 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }