/usr/share/doc/axiom-doc/hypertex/cryptoclass5.xhtml is in axiom-hypertex-data 20120501-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | <?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:m="http://www.w3.org/1998/Math/MathML">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="us-ascii"/>
<title>Axiom Documentation</title>
<style>
html {
background-color: #ECEA81;
}
body {
margin: 0px;
padding: 0px;
}
div.command {
color:red;
}
div.center {
color:blue;
}
div.reset {
visibility:hidden;
}
div.mathml {
color:blue;
}
input.subbut {
background-color:#ECEA81;
border: 0;
color:green;
font-family: "Courier New", Courier, monospace;
}
input.noresult {
background-color:#ECEA81;
border: 0;
color:black;
font-family: "Courier New", Courier, monospace;
}
span.cmd {
color:green;
font-family: "Courier New", Courier, monospace;
}
pre {
font-family: "Courier New", Courier, monospace;
}
</style>
</head>
<body>
<div align="center"><img align="middle" src="doctitle.png"/></div>
<hr/>
<center>
<h2>RCM3720 Cryptography, Network and Computer Security</h2>
<h3>Laboratory Class 5: RSA and public-key cryptosystems</h3>
</center>
<hr/>
<ul>
<li> Read in this file:
<ul>
<li>
<span class="cmd">
)read "S:/Samples/RCM3720/rcm3720.input" )quiet
</span>
</li>
</ul>
</li>
<li> You can leave the "<tt>)quiet</tt>" off if you like. The file
is also available <a href="rcm3720.input">here</a>.
If you obtain it from the
website, save it to a place of your choice, and <tt>read</tt> it
into your Axiom session using the full path, as shown above.
</li>
<li> Now create some large primes and their product:
<ul>
<li> <span class="cmd">r() == rand(2^100)</span></li>
<li> <span class="cmd">p:=nextPrime(r())</span></li>
<li> <span class="cmd">q:=nextPrime(r())</span></li>
<li> <span class="cmd">n:=p*q</span></li>
</ul>
</li>
<li> Choose a value <tt>e</tt> and ensure that it is relatively prime
to your <tt>(p-1)(q-1)</tt>, and determine
<tt>d=e^-1 mod (p-1)(q-1)</tt>. (Use the <tt>invmod</tt> function here).
</li>
<li> Create a plaintext:
<ul>
<li> <span class="cmd">pl:="This is my plaintext."</span></li>
</ul>
</li>
<li> (or any plaintext you like), and convert it to a number using the
<tt>str2num</tt> procedure from the file above:
<ul>
<li> <span class="cmd">pln:=str2num(pl)</span></li>
</ul>
</li>
<li> Encrypt this number using the RSA method:
<ul>
<li> <span class="cmd">ct:=powmod(pln,e,n)</span></li>
</ul>
</li>
<li> and decrypt the result:
<ul>
<li> <span class="cmd">decrypt:=powmod(ct,d,n)</span></li>
<li> <span class="cmd">num2str(decrypt)</span></li>
</ul>
</li>
<li> With a friend, swap your public keys and use them to send
each other a ciphertext encrypted with your friend's public key.
</li>
<li> Now decrypt the ciphertext you have received using your private key.</li>
<li> Now try Rabin: create two large primes <tt>p</tt> and <tt>q</tt> and
ensure that each is equal to 3 mod 4. (You might have to run the
<tt>nextPrime</tt> command a few times until you get primes which work.)
</li>
<li> Create <tt>N=pq</tt> and create a plaintext <tt>pl</tt>, and its
numerical equivalent.
</li>
<li> Determine the ciphertext <tt>c</tt> by squaring your
number mod <tt>N</tt>.
</li>
<li> Determine the <tt>s</tt> and <tt>t</tt> for which <tt>sp+tq=1</tt>
by using the <tt>extendedEuclidean</tt> function.
</li>
<li> Now follow through the Rabin decryption:
<ul>
<li> <span class="cmd">cp:=powmod(c,(p+1)/4,N) </span></li>
<li> <span class="cmd">cq:=powmod(c,(q+1)/4,N)</span></li>
<li>
<span class="cmd">
c1:=(s*p*cq+t*q*cp)::ZMOD N,num2str(c1::INT)
</span>
</li>
<li>
<span class="cmd">
c2:=(s*p*cq-t*q*cp)::ZMOD N,num2str(c2::INT)
</span>
</li>
<li>
<span class="cmd">
c3:=(-s*p*cq-t*q*cp)::ZMOD N,num2str(c3::INT)
</span>
</li>
<li>
<span class="cmd">
c4:=(-s*p*cq+t*q*cp)::ZMOD N,num2str(c4::INT)
</span>
</li>
</ul>
</li>
<li> One of the outputs <tt>c1</tt>, <tt>c2</tt>, <tt>c3</tt> and
<tt>c4</tt> should produce the correct plaintext; the others should be
gibberish.
</li>
<li> As above, swap public keys with a friend, and use those public
keys to encrypt a message to him or her. Now decrypt the ciphertext
you have been given.
</li>
<li> For the el Gamal system, you need a large prime and a primitive
root. Create a large prime <tt>p</tt> and find a primitive root
<tt>a</tt> using.
<ul>
<li> <span class="cmd">a:=primitiveElement()$PF p</span></li>
</ul>
</li>
<li> The <tt>primitiveElement</tt> command is not very efficient, so
if it seems to be taking a long time, abort the computation and try
with another prime.
</li>
<li> Do this in pairs with a friend, so that you each agree on a
large prime and a primitive root.
</li>
<li> Now choose a random value <tt>A</tt>:
<ul>
<li> <span class="cmd">A:=random(p-1)</span></li>
</ul>
</li>
<li> and create your public key <tt>A1=a^A (mod p)</tt>:
<ul>
<li> <span class="cmd">A1:=a^A</span></li>
</ul>
</li>
<li> Swap public keys with your friend.</li>
<li> Create a plaintext <tt>pl</tt> and its number <tt>pln</tt>, and create
the ciphertext as follows (where <tt>A1</tt> is your friend's
public key):
<ul>
<li> <span class="cmd">k:=random(p-1)</span></li>
<li> <span class="cmd">K:=A1^k</span></li>
<li> <span class="cmd">C:=[a^k, K*pln]</span></li>
</ul>
</li>
<li> This pair <tt>C</tt> is the ciphertext you send to your friend.</li>
<li> Now decrypt the ciphertext you have been sent:
<ul>
<li> <span class="cmd">K:=C.1 ^ A</span></li>
<li> <span class="cmd">m:=C.2/K</span></li>
<li> <span class="cmd">num2str(m::INT)</span></li>
</ul>
</li>
</ul>
</body>
</html>
|