<?xml version="1.0" encoding="UTF-8"?>
<Worksheet>
<Version major="12" minor="0"/>
<Label-Scheme value="2" prefix=""/>
<View-Properties presentation="true"></View-Properties>
<MapleNet-Properties elisiondigitsbefore="100" labelling="true" indentamount="4" elisiontermsthreshold="10000" ansi="false" errorbreak="1" useclientjvm="true" echo="1" imaginaryunit="I" labelwidth="20" plotdriver="openviz" elisiondigitsafter="100" plotoutput="terminal" rtablesize="10" elisiontermsbefore="100" elisiondigitsthreshold="10000" typesetting="standard" plotdevice="inline" verboseproc="1" showassumed="1" errorcursor="false" longdelim="true" plotoptions="" quiet="false" elisiontermsafter="100" screenwidth="79" preplot="" prettyprint="3" displayprecision="-1" warnlevel="3" screenheight="25" latexwidth="6.0" postplot="" prompt="&gt; " ShowLabels="true"/>
<Styles><Font name="Ordered List 1" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Annotation Text" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 2" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 3" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 4" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 5" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Author" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Annotation Title" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="18" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Warning" background="[255,255,255]" bold="false" executable="false" family="Monospaced" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Maple Input Placeholder" background="[255,255,255]" bold="true" executable="true" family="Monospaced" foreground="[200,0,200]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="true"/>
<Font name="Maple Plot" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Code" background="[255,255,255]" bold="false" executable="false" family="Monospaced" foreground="[255,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Line Printed Output" background="[255,255,255]" bold="false" executable="false" family="Monospaced" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Text Output" background="[255,255,255]" bold="false" executable="false" family="Monospaced" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Diagnostic" background="[255,255,255]" bold="false" executable="false" family="Monospaced" foreground="[40,120,40]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Inert Output" background="[255,255,255]" bold="false" executable="true" family="Times New Roman" foreground="[144,144,144]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Normal" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Hyperlink" background="[255,255,255]" bold="false" executable="false" family="Serif" foreground="[0,128,128]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="true" placeholder="false"/>
<Font name="Maple Output" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Dash Item" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Math" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Maple Input" background="[255,255,255]" bold="true" executable="true" family="Monospaced" foreground="[255,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Output" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Input" background="[255,255,255]" bold="false" executable="true" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Header and Footer" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="10" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Error" background="[255,255,255]" bold="false" executable="false" family="Monospaced" foreground="[255,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Title" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="18" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Page Number" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="10" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 1" background="[255,255,255]" bold="true" executable="false" family="Serif" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="18" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Text" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Bullet Item" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Equation Label" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 4" background="[255,255,255]" bold="false" executable="false" family="Serif" foreground="[0,0,0]" italic="true" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 3" background="[255,255,255]" bold="true" executable="false" family="Serif" foreground="[0,0,0]" italic="true" opaque="false" readonly="false" size="14" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 2" background="[255,255,255]" bold="true" executable="false" family="Serif" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="16" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Dictionary Hyperlink" background="[255,255,255]" bold="false" executable="false" family="Serif" foreground="[147,0,15]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="true" placeholder="false"/>
<Font name="List Item" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Layout name="Maple Output" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.3" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Ordered List 1" alignment="left" bullet="numeric" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix=""/>
<Layout name="Dash Item" alignment="left" bullet="dash" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Ordered List 2" alignment="left" bullet="alphabetic" firstindent="0" leftmargin="36" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix=""/>
<Layout name="Ordered List 3" alignment="left" bullet="roman" firstindent="0" leftmargin="72" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix=""/>
<Layout name="Ordered List 4" alignment="left" bullet="ALPHABETIC" firstindent="0" leftmargin="108" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix=""/>
<Layout name="Ordered List 5" alignment="left" bullet="ROMAN" firstindent="0" leftmargin="144" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix=""/>
<Layout name="Author" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="8" spacebelow="8" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Warning" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Annotation Title" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="12" spacebelow="12" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Maple Plot" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Error" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Title" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="12" spacebelow="12" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Line Printed Output" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="any" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 1" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="8" spacebelow="4" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Diagnostic" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="any" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Text Output" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="newline" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Bullet Item" alignment="left" bullet="dot" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 4" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Normal" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 3" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 2" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="8" spacebelow="2" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="List Item" alignment="left" bullet="indent" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Pencil-style name="Pencil 5" pen-color="[255,0,0]" pen-height="5.0" pen-width="5.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 4" pen-color="[0,0,255]" pen-height="3.0" pen-width="3.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 3" pen-color="[0,0,0]" pen-height="3.0" pen-width="3.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 2" pen-color="[0,0,255]" pen-height="1.0" pen-width="1.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 1" pen-color="[0,0,0]" pen-height="1.0" pen-width="1.0" pen-opacity="1.0"/>
<Highlighter-style name="Highlighter 2" pen-color="[255,204,0]" pen-height="14.0" pen-width="14.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 1" pen-color="[255,153,255]" pen-height="12.0" pen-width="8.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 4" pen-color="[0,255,255]" pen-height="32.0" pen-width="32.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 3" pen-color="[51,255,0]" pen-height="24.0" pen-width="24.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 5" pen-color="[255,255,0]" pen-height="48.0" pen-width="48.0" pen-opacity="0.8"/>
</Styles>
<Task-table>
    <Task-category name="&lt;default&gt;">
    </Task-category>
</Task-table>
<Task>
</Task>
<Text-field style="Text" size="18" bold="true" layout="Title"><Font bold="true" size="18">Using RSA</Font></Text-field>
<Text-field style="Author" layout="Author"><Font encoding="UTF-8">\302\251</Font>2007 by Mike May, S.J., Saint Louis University - maymk@slu.edu</Text-field>
<Text-field style="Normal" layout="Normal">An introduction to the RSA cryptographic system</Text-field>
<Group labelreference="L67" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">restart:</Text-field>
</Input>
</Group>
<Section collapsed="false" MultipleChoiceAnswerIndex="-1" MultipleChoiceRandomizeChoices="false" TrueFalseAnswerIndex="-1" EssayAnswerRows="5" EssayAnswerColumns="60"><Title>
<Text-field style="Heading 1" layout="Heading 1">Setting up RSA to encode numbers</Text-field></Title>
<Text-field style="Text" layout="Normal">The first thing to do to use RSA is to find two large primes.  For this worksheet we will be looking for primes that are about 80 digits long.  (I chose 80 digits because that is what easily fits on one line.)  We do this with the rand and nextprime functions in Maple.</Text-field>
<Group labelreference="L38" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">M1 := rand(10^80)();
M2 := rand(10^80)();
P1 := nextprime(M1);
P2 := nextprime(M2);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">The use of a random number function in the selection of the primes is intended to make them hard to guess.  The output has been converted to Maple input so that we can work with repeatable computations.</Text-field>
<Group labelreference="L60" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">M1 := 99596883909465520335617712166467577059926068276305009675299763431340064249105338;
M2 := 34633129088861013688643347733731974176548310874222673528866121995231476726634212;
P1 := 99596883909465520335617712166467577059926068276305009675299763431340064249105379;
P2 := 34633129088861013688643347733731974176548310874222673528866121995231476726634233;</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">I need to compute n, the product of the two primes, and the number of elements of Z_n relatively prime to n, or the product of one less than each of the primes.</Text-field>
<Group labelreference="L63" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">n := P1*P2;
n2 := (P1-1)*(P2-1);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">I now need to decide on a value for e, the encrypting number.  Since e will be public, I don't need to worry about random generation.  I can consider numbers that will be easy to work with mathematically.  Since I will want e to be relatively prime to n2, it is best if I choose e to be prime.  For computational reasons it is nicer if e represented base 2 should be almost all zeroes.  Thus we choose a Fermat prime, that is a number of the form 2^k+1, where k is a power of 2.  Following a number of sources we use 2^16+1.</Text-field>
<Group labelreference="L41" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">e:= 2^16+1;  isprime(e); gcd(e,n2);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">Recall that we had to make sure that e is relatively prime to n2.  That is easier because we have chosen e to be prime.  Now we need to compute d, the multiplicative inverse of e mod n2.  We could do that directly with the extended Euclidean algorithm, but we will just use the modular arithmetic of Maple.</Text-field>
<Group labelreference="L58" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">d := eval(1/e mod n2);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">We are ready to define encoding and decoding procedures.</Text-field>
<Group labelreference="L52" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">encoder := (a,e,n) -&gt; Power(a,e) mod n:
decoder := (a,d,n) -&gt; Power(a,d) mod n:</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">A quick note on programming is in order here.  </Text-field>
<Text-field style="Text" layout="Normal">The use of the Power (a, d) mod n construction here than a^d mod n is important.  The second construction would try to compute a^d as an intermediate step and if a=2, then a^d has more digits than there are atoms in the universe.</Text-field>
<Text-field style="Text" layout="Normal"></Text-field>
<Text-field style="Text" layout="Normal">We obviously want to check that the procedures reverse each other, at least for a small sample of messages.</Text-field>
<Group labelreference="L68" drawlabel="true">
<Input>
<Text-field prompt="&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ShkZWNvZGVyRidGL0YyRjVGOEY7LUZpbjYpLUYjNilGK0Zhby1GLDYoUSJkRidGL0YyRjVGOEY7RmFvRltwRl5wRjtGL0ZgcEY1RjhGYnBGZHBGZnBGXnBGOw==</Equation></Text-field>
</Input>
</Group>
</Section>
<Section collapsed="true" MultipleChoiceAnswerIndex="-1" MultipleChoiceRandomizeChoices="false" TrueFalseAnswerIndex="-1" EssayAnswerRows="5" EssayAnswerColumns="60"><Title>
<Text-field style="Heading 2" layout="Heading 2">Exercises</Text-field></Title>
<Text-field style="Text" layout="Normal">1)  The chosen primes let us encode and decode messages that are numbers approximately in the range of 0 to 10^159.  Randomly pick 5 numbers in that range and verify that encoding and decoding act as inverse operations on these numbers.</Text-field>
<Group labelreference="L43" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal"></Text-field>
<Text-field style="Text" layout="Normal">2)  Of the numbers found so far, explain which numbers I want to publish, which ones I want to save but keep secret, and which ones I want to destroy and forget if I am using RSA as a public key system.</Text-field>
<Group labelreference="L65" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal"></Text-field>
<Text-field style="Text" layout="Normal">3)  Randomly pick two primes of your own in the 1-10^80 range and prepare your own keys.  Test that your keys encrypt and decrypt on two numbers of your choice.  (You probably don't want to reuse the names n, e, or d, since we will continue to use these numbers in later exercises.</Text-field>
<Group labelreference="L36" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal"></Text-field>
<Text-field style="Text" layout="Normal">4)  Post your public key and modulus to the bulletin board so that others in the class can send you messages.  (Do not post your secret key.)</Text-field>
<Group labelreference="L37" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
</Section>
<Section collapsed="true" MultipleChoiceAnswerIndex="-1" MultipleChoiceRandomizeChoices="false" TrueFalseAnswerIndex="-1" EssayAnswerRows="5" EssayAnswerColumns="60"><Title>
<Text-field style="Heading 1" layout="Heading 1">Encoding messages rather than numbers</Text-field></Title>
<Text-field style="Text" layout="Normal">Now we want to turn our attention to encoding messages.  Following the pattern from earlier work, if we want to turn our message into into a single number, the trick is to use convert to change a message from ASCII to a string of decimal equivalents, then convert each of the decimal numbers into a two digit hex number, concatenate (string together) the hex numbers into one big number, then convert it back to a decimal number.  We can then encode our message number, convert it to a hex number and store it in some reasonable form.</Text-field>
<Text-field style="Text" layout="Normal"></Text-field>
<Text-field style="Text" layout="Normal">Recall that we had a problem with hex conversion before.  If the decimal equivalent of the ASCII character is less than 16, the hex number is only one digit long, and we want to assume characters contribute 2 hex digits to keep placement straight.  (In particular the &quot;return&quot; character is equivalent to 13.)  The procedure twodigithex converts with a two digit output.</Text-field>
<Group labelreference="L61" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">twodigithex := a -&gt; substring(convert(a+256,hex),2..3):</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">We are ready to start with a small message.</Text-field>
<Group labelreference="L47" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">Message1 := &quot;Good morning Mr. Phelps,
This morning we look at RSA.
3rd line&quot;;</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">We want a procedure to convert this to a number.</Text-field>
<Group labelreference="L48" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">shortconverter := proc(messagestring)
  local stringofhex, lengthofmess, hexstring, i:
    #First we convert the ASCII string to a list of decimal equivalents
    #Then we convert thedecimal numbers to hex equivalents
  stringofhex := map(twodigithex, convert(messagestring,bytes)):
print(stringofhex);
  lengthofmess := nops(stringofhex):
print(lengthofmess);
    #Now we concatenate the hex numbers
  hexstring := cat(seq(stringofhex[i],i=1..lengthofmess)):
print(hexstring);
    #Finally we convert the big number back to decimal
  convert(hexstring,decimal,hex):
end:</Text-field>
</Input>
</Group>
<Group labelreference="L42" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">MessageAsNumber1 := shortconverter(Message1);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">Next we want to encode our number and convert it to hex for easy handling.</Text-field>
<Group labelreference="L54" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">SecretHex1 := convert(encoder(MessageAsNumber1,e,n),hex);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">This does not look very easy to copy back and forth.  (I am sure I would make a mistake if I tried to type a copy of a string that long.)  To give a nice form to the output, I want to pad the message out with leading zeroes, then break it into blocks of a nice size.  For today, I think 10 characters forms a nice block size.</Text-field>
<Group labelreference="L50" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">MessageLength := length(SecretHex1);SecretHex2 := cat(seq(&quot;0&quot;,counter =    1..(MessageLength-(floor(MessageLength/10)*10))),SecretHex1);SecretMessage := [seq(substring(SecretHex2,10*i-9..10*i),i=1..ceil(MessageLength/10))];</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">Now we want to verify that we can put the message back together and decode it.  We define a procedure for converting the vector of hexblock into a single number.</Text-field>
<Group labelreference="L59" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">hexvectodec := (hexvec,size) -&gt; 
         convert(cat(seq(hexvec[i],i=1..size)),decimal,hex):</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">Now we can convert our message back to a decoded number.  We should get an answer equal to MessageNumber1 above.</Text-field>
<Group labelreference="L45" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">NewNumber1 := decoder(hexvectodec(SecretMessage,14),d,n);convert(NewNumber1,hex);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">We also want a procedure for turning the decoded number back into a message.</Text-field>
<Group labelreference="L46" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">numtostring := proc(bignum)
local hexstr1, listlength, declist, i:
#convert to a hex string
hexstr1 := convert(bignum,hex):
#make sure the hex string has even length
if (length(hexstr1) mod 2) = 1 then hexstr1 := cat(`0`,hexstr1) fi;
#compute the number of characters
listlength := length(hexstr1)/2:
#convert to a vector of decimal numbers
declist := linalg[vector](listlength);
for i from 1 to listlength do
declist[i] := convert(substring(hexstr1,2*i-1..2*i),decimal,hex);
od;
#convert the vector to a list, then to an ASCII string
convert(convert(convert(declist,list),bytes),name);
end:</Text-field>
</Input>
</Group>
<Group labelreference="L56" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal">numtostring(NewNumber1);</Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">There is one more issue to deal with.  For the procedures above to work, we have to restrict ourselves to messages that encode as numbers less than n.  A message of length t encodes as a number less than 256^t.</Text-field>
<Group labelreference="L40" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="_pstyle19" font_style_name="_pstyle19" superscript="false" placeholder="false" executable="false" selection-placeholder="false" italic="false" size="12" bold="false" subscript="false" family="Times New Roman" opaque="false" underline="false" background="[255,255,255]" readonly="false" foreground="[0,0,0]" layout="_pstyle19" alignment="left" firstindent="0" spacebelow="0" linebreak="space" rightmargin="0" bulletsuffix="" pagebreak-before="false" leftmargin="0" linespacing="0.0" initial="0" layout_style_name="_pstyle19" spaceabove="0" bullet="none"></Text-field>
</Input>
</Group>
<Group labelreference="L62" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="_cstyle18" font_style_name="_cstyle18" superscript="false" placeholder="false" executable="false" selection-placeholder="false" italic="false" size="12" bold="false" subscript="false" family="Times New Roman" opaque="false" underline="false" background="[255,255,255]" readonly="false" foreground="[0,0,0]" layout="_pstyle19" alignment="left" firstindent="0" spacebelow="0" linebreak="space" rightmargin="0" bulletsuffix="" pagebreak-before="false" leftmargin="0" linespacing="0.0" initial="0" layout_style_name="_pstyle19" spaceabove="0" bullet="none"></Text-field>
</Input>
</Group>
</Section>
<Section collapsed="true" MultipleChoiceAnswerIndex="-1" MultipleChoiceRandomizeChoices="false" TrueFalseAnswerIndex="-1" EssayAnswerRows="5" EssayAnswerColumns="60"><Title>
<Text-field style="Heading 2" layout="Heading 2">Exercises</Text-field></Title>
<Text-field style="Text" layout="Normal">5)  What is the maximum length of a message that we can encode with n chosen as above?</Text-field>
<Group labelreference="L66" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">6)  Enter a message of about 50 characters and encode it Using the n and e defined above. </Text-field>
<Group labelreference="L49" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">7)  Verify that you can decrypt the message with the secret key.</Text-field>
<Group labelreference="L35" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Normal" layout="Normal">8)  For the rest of this worksheet, Fr. May's modulus is
<Font encoding="UTF-8">145790709434263657193410815968586298032651591491182486164339\134</Font>
<Font encoding="UTF-8">752298049755073623061549604680218687683561183675344052519958\134</Font></Text-field>
<Text-field style="Normal" layout="Normal">7698019954839165932427842278373706998741</Text-field>
<Text-field style="Normal" layout="Normal">and his encrypting key is</Text-field>
<Text-field style="Normal" layout="Normal">65537.</Text-field>
<Text-field style="Normal" layout="Normal">Encrypt your short message and send it to him through the bulletin board.</Text-field>
<Group labelreference="L39" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">9)  Obtain the public keys of two other people in the class and send them a short encrypted message via the bulletin board.</Text-field>
<Group labelreference="L57" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">10)  Respond to the messages you get with encrypted messages.</Text-field>
<Group labelreference="L53" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
<Text-field style="Text" layout="Normal">11)  Make a shorter RSA worksheet that you can use as an application for encrypting and decrypting.</Text-field>
<Group labelreference="L51" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
</Section>
<Group labelreference="L64" drawlabel="true">
<Input>
<Text-field prompt="&gt; " style="_cstyle18" font_style_name="_cstyle18" superscript="false" placeholder="false" executable="false" selection-placeholder="false" italic="false" size="12" bold="false" subscript="false" family="Times New Roman" opaque="false" underline="false" background="[255,255,255]" readonly="false" foreground="[0,0,0]" layout="_pstyle19" alignment="left" firstindent="0" spacebelow="0" linebreak="space" rightmargin="0" bulletsuffix="" pagebreak-before="false" leftmargin="0" linespacing="0.0" initial="0" layout_style_name="_pstyle19" spaceabove="0" bullet="none"></Text-field>
</Input>
</Group>
<Text-field style="_cstyle15" font_style_name="_cstyle15" superscript="false" placeholder="false" executable="false" selection-placeholder="false" italic="false" size="12" bold="false" subscript="false" family="Times New Roman" opaque="false" underline="false" background="[255,255,255]" readonly="false" foreground="[0,0,0]" layout="_pstyle23" alignment="left" firstindent="0" spacebelow="0" linebreak="space" rightmargin="0" bulletsuffix="" pagebreak-before="false" leftmargin="0" linespacing="0.0" initial="0" layout_style_name="_pstyle23" spaceabove="0" bullet="none">Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.</Text-field>
<Text-field style="_cstyle22" font_style_name="_cstyle22" superscript="false" placeholder="false" executable="false" selection-placeholder="false" italic="false" size="12" bold="false" subscript="false" family="Times New Roman" opaque="false" underline="false" background="[255,255,255]" readonly="false" foreground="[0,0,0]" layout="_pstyle24" alignment="left" firstindent="0" spacebelow="0" linebreak="space" rightmargin="0" bulletsuffix="" pagebreak-before="false" leftmargin="0" linespacing="0.0" initial="0" layout_style_name="_pstyle24" spaceabove="0" bullet="none"></Text-field>
<Text-field style="_pstyle25" font_style_name="_pstyle25" superscript="false" placeholder="false" executable="false" selection-placeholder="false" italic="false" size="12" bold="false" subscript="false" family="Times New Roman" opaque="false" underline="false" background="[255,255,255]" readonly="false" foreground="[0,0,0]" layout="_pstyle25" alignment="left" firstindent="0" spacebelow="0" linebreak="space" rightmargin="0" bulletsuffix="" pagebreak-before="false" leftmargin="0" linespacing="0.0" initial="0" layout_style_name="_pstyle25" spaceabove="0" bullet="none"></Text-field><Presentation-Block>
<Group view="presentation" hide-input="false" hide-output="true" inline-output="false" labelreference="L1" drawlabel="true">
<Input>
<Text-field style="Text" layout="Normal"><Equation executable="false" style="2D Math" input-equation="" display="LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2I1EhRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYn">LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic=</Equation></Text-field>
</Input>
</Group></Presentation-Block>
</Worksheet>