{VERSION 4 0 "SUN SPARC SOLARIS" "4.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 Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 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 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 }} {SECT 0 {EXCHG {PARA 0 "" 0 "" {TEXT -1 92 "This worksheet contains so me functions that can be used to translate encrypt a text file. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 109 " Text files are stored as ASCII text. We use readbytes(textfile, infin ity) to read the whole file, producing " }}{PARA 0 "" 0 "" {TEXT -1 106 "a list of numbers between 0 and 127 each representing a characte rs in the text. I've created lists below" }}{PARA 0 "" 0 "" {TEXT -1 124 "for the numbers corresponding to capital and ordinary letters (Ma jletters[], Minletters), the digits 0 to 9 (Numberlist[]), " }}{PARA 0 "" 0 "" {TEXT -1 115 "the space, tab and newline (Spacelist[]), the \+ punctuation marks (Punctlist[]), other symbols (Otherlist[]) and for \+ " }}{PARA 0 "" 0 "" {TEXT -1 62 "the numbers that do not correspond to characters (Badlist[]). " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 118 "badlist:=[]:\nfor i from 1 to 8 do badlist:= [op(badlist),i] od: \+ \nfor i from 12 to 31 do badlist := [op(badlist),i] od:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "spacelist:=[9,10,11,32]:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "punctlist:=[33,44,46,58,59,6 3]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "numberlist:= [48,49, 50,51,52,53,54,55,56,57]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 73 "majletters:=[]:\nfor i from 65 to 90 do majletters:=[op(majletters ),i] od:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 76 "minletters := [ ]:\nfor i from 97 to 122 do minletters:=[op(minletters),i] od:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 153 "otherlist:=[]:\nfor i from \+ 34 to 43 do otherlist:=[op(otherlist),i] od:\notherlist:= [ops(otherli st),45,47, 60,61,62,64,91,92,93,94,95,96,123,124,125,126]:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 413 "The function trim1(text) takes a string \+ of ASCII numbers and produces a list of numbers from 0 to 26. It trim s out the non-characters, the symbols, the digits and the punctuation \+ marks. It replaces all space characters with 0 and any letter (whethe r capital or ordinary ) with the corresponding number between 1 and 26 . The function can be easily changed to accomodate puctuation marks o r digits, or whatever. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 350 "trim1:= proc(text)\nlocal i, outtext;\n\nouttext:=[];\nfor i from 1 t o nops(text) do\n if member(text[i],spacelist) then \n outtext := [op(outtext),0]; \n elif member(text[i], majletters) then \n outt ext := [op(outtext),text[i]-64]: \n elif member (text[i], minletters) then \n outtext := [op(outtext), text[i]-96]:\n fi;\nod;\nRETURN( outtext);\nend;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&trim1GR6#%%textG 6$%\"iG%(outtextG6\"F+C%>8%7\"?(8$\"\"\"F2-%%nopsG6#9$%%trueG@(-%'memb erG6$&F66#F1%*spacelistG>F.7$-%#opG6#F.\"\"!-F:6$F<%+majlettersG>F.7$F A,&FF.7$FA,&F " 0 "" {MPLTEXT 1 0 211 "ascii1 := proc(text)\nlocal i, outtext;\n \nouttext:=[]:\nfor i from 1 to nops(text) do\n if (text[i]=0) then o uttext := [op(outtext),32]; \n else outtext := [op(outtext),text[i]+ 64];\n fi;\nod;\nRETURN(outtext);\nend;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%'ascii1GR6#%%textG6$%\"iG%(outtextG6\"F+C%>8%7\"?(8$\"\"\"F2-% %nopsG6#9$%%trueG@%/&F66#F1\"\"!>F.7$-%#opG6#F.\"#K>F.7$F?,&F:F2\"#kF2 -%'RETURNGFAF+F+F+" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 76 "Here is an \+ example eading the file \"textfile\" which has the following text, " } }{PARA 0 "" 0 "" {TEXT -1 38 "\"This is a text file to be encrypted.\" " }}{PARA 0 "" 0 "" {TEXT -1 109 "We then apply trim1() and then ascii (). The latter two are shorter because the period was removed by trim ()." }}{PARA 0 "" 0 "" {TEXT -1 59 "Finally we write to \"outp\". The n file \"outp\" has the text." }}{PARA 0 "" 0 "" {TEXT -1 38 "\"THIS I S A TEXT FILE TO BE ENCRYPTED \"" }}{PARA 0 "" 0 "" {TEXT -1 71 "You n eed to use fflush to force the output to be written into the file." }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "H:= readbytes(textfile,infi nity);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%\"HG7G\"#%)\"$/\"\"$0\"\"$ :\"\"#KF(F)F*\"#(*F*\"$;\"\"$,\"\"$?\"F,F*\"$-\"F(\"$3\"F-F*F,\"$6\"F* \"#)*F-F*F-\"$5\"\"#**\"$9\"\"$@\"\"$7\"F,F-\"$+\"\"#Y\"#5" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "HH:= trim1(H);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%#HHG7F\"#?\"\")\"\"*\"#>\"\"!F(F)F*\"\"\"F*F&\"\"&\"# CF&F*\"\"'F(\"#7F,F*F&\"#:F*\"\"#F,F*F,\"#9\"\"$\"#=\"#D\"#;F&F,\"\"%F *" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "HHH:=ascii1(HH);" }} {PARA 12 "" 1 "" {XPPMATH 20 "6#>%$HHHG7F\"#%)\"#s\"#t\"#$)\"#KF(F)F* \"#lF*F&\"#p\"#))F&F*\"#qF(\"#wF,F*F&\"#zF*\"#mF,F*F,\"#y\"#n\"##)\"#* )\"#!)F&F,\"#oF*" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "nops(H) ; nops(HH); nops(HHH);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#P" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"#O" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#\"#O" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "writebytes(outp,H HH); fflush(outp);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#O" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "save `textproc.m`;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 109 "save badlist, spacelist, numberlis t, punctlist, otherlist, majletters, minletters, trim1, ascii1, \"text proc\";" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "21 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }