{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 }{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 "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 "Heading 2" 3 4 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 8 2 0 0 0 0 0 0 -1 0 } {PSTYLE "Author" 0 19 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 8 8 0 0 0 0 0 0 -1 0 }{PSTYLE "" 3 256 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 257 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 22 "Handling text in Maple" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 19 "" 0 "" {TEXT -1 55 "Mike O 'Sullivan\nSan Diego State University\nJanuary 2005" }}{PARA 257 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 112 "This workshee t sets up a simple correspondence between the alphabet and numbers.\nI show three different methods." }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 35 "Using a list to define the alphabet" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 107 "The following list contains the alphabet and space, repr esented by _. The function translate_to_numbers()" }}{PARA 0 "" 0 " " {TEXT -1 123 "will take a list of letters, find the letter in ordere d_alphabet[], and return the appropriate index: 1 for A, 2 for B etc. " }}{PARA 0 "" 0 "" {TEXT -1 76 "Note that I started the list with \"_ \" and have to subtract 1 to get 0 for _." }}{PARA 0 "" 0 "" {TEXT -1 160 "The function translate_to_letters() is simpler. Given a list of \+ numbers, all between 0 and 26, it returns the letter ordered_alphab et[N+1] for the number N." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 131 "This is easy to rewrite to accomodate punctuation marks, or whatever characters you want to include (and whatever index ing system)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 102 "ordered_al phabet := [_, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 279 " translate_to_numbers := proc(let_list)\nlocal i,j, num_list;\n\nnum_li st := [];\nfor i from 1 to nops(let_list) do\n for j from 1 to nops(o rdered_alphabet) do\n if let_list[i] = ordered_alphabet[j] then\n \+ num_list:= [op(num_list),j-1];\n fi;\n od;\nod;\nRETURN(num_l ist);\nend;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 197 "translate_t o_letters := proc(num_list)\nlocal j, let_list;\n\nlet_list :=[];\nfo r j from 1 to nops(num_list) do\n let_list:= [op(let_list), ordered_a lphabet[num_list[j]+1]];\nod;\nRETURN(let_list);\nend;" }}}{SECT 1 {PARA 4 "" 0 "" {TEXT -1 7 "Example" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "b_let := [T,H,E,_,C,A,T,_,I,S,_,O,U,T,_,O,F,_,T,H,E,_ ,B,A,G,Z];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "b_num := tran slate_to_numbers(b_let);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "translate_to_letters(b_num);" }}}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 45 "Using a string for the alphabet and the text." }}{EXCHG {PARA 0 " " 0 "" {TEXT -1 105 "Here is a method based on the searchtext() which \+ ignores case. Use SearchText if you want case specific." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 125 "The two procedure s below have an optional second argument, refered to as args[2]. It i s the alphabet that you want to use. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 248 "translate_to_numbers:=proc(str) \nlocal alphabet, po ssition; \n\nif nargs<2 then alphabet := \"ABCDEFGHIJKLMNOPQRSTUVWXYZ \" \nelse alphabet:=args[2] end if; \npossition:=[seq(searchtext(str[i ],alphabet)-1,i=1..length(str))]; RETURN(possition) \nend proc:\n\n" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 215 "translate_to_letters:=pro c(lst)\nlocal alphabet, str;\nif nargs<2 then alphabet:=\"ABCDEFGHIJKL MNOPQRSTUVWXYZ\" \nelse alphabet:=args[2] end if;\nstr:=cat(seq(alphab et[lst[k]+1],k=1..nops(lst)));\nRETURN(str);\nend proc: \n\n" }}} {SECT 1 {PARA 4 "" 0 "" {TEXT -1 7 "Example" }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 146 "alph:=\" ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\ntxt:=\"Thi s is a string to be encrypted\";\nlst:=translate_to_numbers(txt,alph); \ntranslate_to_letters(lst,alph);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 172 "alph:=\" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ RSTUVWXYZ\";\ntxt:=\"This is a string to be encrypted\";\nlst:=transla te_to_numbers(txt,alph);\ntranslate_to_letters(lst,alph);" }}}}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 12 "Using ascii " }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 223 "On c omputers each letter is stored as a byte, that is 8 bits. \nThe eigth bit is a check bit, so there are really 128 different \"letters. \nT he following shows the \"letter\" equivalent of the numbers 0 to 127 \+ within Maple.\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 97 "ls_num : =[seq(i, i=0..127)];\nls_let := convert(ls_num, bytes);\nls_num2 := co nvert(ls_let, bytes);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 182 "Notice \+ that the letters for 0 to 9 and for 11 to 33 and for 127 are all a squ are (representing white space). \nThe letter for 10 is a newline. A \+ space in a string corresponds to 32." }}{PARA 0 "" 0 "" {TEXT -1 57 "I f we take all the white space and the newline out, then " }}{PARA 0 " " 0 "" {TEXT -1 37 "we have altogether 128-34=94 letters." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 119 "The following fun ction converts the numbers that can arise from text (with pucntuation) to\na number between 0 and 94. " }}{PARA 0 "" 0 "" {TEXT -1 193 "The n you can use a cryptosystem mod 95. You can alter the code to omit s ome of the punctuation.\nAlso I'm not sure how it will handle the quot e character \", since it is used to define a string." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 156 "trim_num:= proc(in_num) \nlocal out_num:\n if in_num = 32\n \+ then out_num :=0;\n else\n out_num := in_num -34;\n end if ;\nRETURN(out_num);\nend proc:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 159 "expand_num:= proc(in_num) \nlocal out_num:\n if o ut_num = 0\n then out_num :=32;\n else\n out_num := in_num + 34;\n end if;\nRETURN(out_num);\nend proc:\n" }}}{SECT 1 {PARA 4 "" 0 "" {TEXT -1 7 "Example" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 137 "Here \+ we take a text message, convert to a list of numbers, and then use tri m_num to get \nnumbers in the range 0 to 94 for the plain text." }} {PARA 0 "" 0 "" {TEXT -1 154 "Then we encrypt using a Caesar cipher wi th shift defined below, use expand_num to \nget back to ascii equivale nts of letters, and convert back to a string." }}{PARA 0 "" 0 "" {TEXT -1 56 "You should reverse the process to get the original text. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "shift := 7;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 212 "Textmessage:= \"Raindrops the size of bullets thundered on the castle windows for days on end; the lake \+ rose, the flower beds turned into muddy streams, and Hagrid's pumpkins swelled to the size of garden sheds.\";" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "pnums := convert(Textmessage, bytes);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "plaintext := map(trim_num, nums);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "ciphertext := map(x -> x+ shift mod 95, plaintext);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "cnums := map(expand_num, ciphertext);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 22 "convert(cnums, bytes);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}}}}}{MARK "0 1 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }