/usr/share/doc/axiom-doc/hypertex/cryptoclass3.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 216 217 218 219 220 221 | <?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 3: Number Theory</h3>
</center>
<hr/>
<ul>
<li> Check out the commands <tt>gcd</tt> and <tt>factor</tt>, and test them
on different numbers, small and large.
</li>
<li> Axiom provides a few useful commands for taking apart the factors of an
object:
<ul>
<li> <span class="cmd">n:=5040</span></li>
<li> <span class="cmd">f:=factor(n)</span></li>
<li> <span class="cmd">numf:=numberOfFactors(f)</span></li>
<li> <span class="cmd">fs:=[nthFactor(f,i) for i in 1..numf]</span></li>
<li> <span class="cmd">es:=[nthExponent(f,i) for i in 1..numf]</span></li>
<li> <span class="cmd">reduce(*,[fs.i^es.i for i in 1..numf])</span></li>
</ul>
</li>
<li> The last command simply multiplies all the factors to their powers.</li>
<li> Check out the commands <tt>prime?</tt>, <tt>nextPrime</tt> and
<tt>prevPrime</tt>.
</li>
<li> To compute the <tt>i</tt>-th prime, we can construct a <i>stream</i>
(an infinite list) in Axiom:
<ul>
<li>
<span class="cmd">
primes:Stream Integer:=[i for i in 2.. | prime? i]
</span>
</li>
</ul>
</li>
<li> Now we can find, for example, the 100-th prime, and the 2500-th prime:
<ul>
<li> <span class="cmd">primes.100</span></li>
<li> <span class="cmd">primes.2500</span></li>
</ul>
</li>
<li> Create random 10 digit primes:
<ul>
<li> <span class="cmd">p := nextPrime(random(10^10))</span></li>
<li> <span class="cmd">q := nextPrime(random(10^10))</span></li>
</ul>
</li>
<li> Now multiply them and factor the product. How long did it take?</li>
<li> Try the same thing with 12 digit primes and 15 digit primes.</li>
<li> The extended Euclidean algorithm is implemented by the command
<tt>extendedEuclidean</tt>. Here's how to use it:
<ul>
<li> <span class="cmd">a:=1149</span></li>
<li> <span class="cmd">b:=3137</span></li>
<li> <span class="cmd">g:=extendedEuclidean(a,b)</span></li>
<li> <span class="cmd">s:=g.coef1</span></li>
<li> <span class="cmd">t:=g.coef2</span></li>
</ul>
</li>
<li> and now test them:
<ul>
<li> <span class="cmd">s*a+t*b</span></li>
</ul>
</li>
<li> Try this on a few other numbers.</li>
<li> Axiom uses the command <tt>positiveRemainder</tt> instead of
<tt>mod</tt> command, so let's define <tt>mod</tt> to be a renaming
of the <tt>positiveRemainder</tt> function:
<ul>
<li> <span class="cmd">mod ==> positiveRemainder</span></li>
</ul>
</li>
<li> Now the commands <tt>addmod</tt>, <tt>submod</tt>, <tt>mulmod</tt>, and
<tt>invmod</tt> can be used to perform modular arithmetic. Here's a few
examples; first a simple modulus calculation:
<ul>
<li> <span class="cmd">-10 mod 3</span></li>
</ul>
</li>
<li> Addition, subtraction and multiplication mod 14:
<ul>
<li> <span class="cmd">addmod(10,13,14)</span></li>
<li> <span class="cmd">submod(17,23,14)</span></li>
<li> <span class="cmd">mulmod(13,27,14)</span></li>
</ul>
</li>
<li> Powers and inverses:
<ul>
<li> <span class="cmd">powmod(19,237,14)</span></li>
<li> <span class="cmd">invmod(11,14)</span></li>
</ul>
</li>
<li> Find out what happens if you try to take an inverse of a number not
relatively prime to the modulus:
<ul>
<li> <span class="cmd">invmod(12,14)</span></li>
</ul>
</li>
<li> Try these command with a few other numbers, and test out the examples in
the notes.
</li>
<li> The second method, which can be more powerful, is to treat all numbers
as elements of the residue values 0 to <tt>n-1</tt>. This can be done with
the <tt>IntegerMod</tt> construction, or its abbreviation <tt>ZMOD</tt>.
Here's a few examples:
<ul>
<li> <span class="cmd">a:=11::ZMOD 14</span></li>
</ul>
</li>
<li> This declares the variable <tt>a</tt> to be a member of the residue
class modulo 14. Now all arithmetic including <tt>a</tt> will be
reduced to this same class of values:
<ul>
<li> <span class="cmd">a+25</span></li>
<li> <span class="cmd">a*39</span></li>
<li> <span class="cmd">a^537</span></li>
</ul>
</li>
<li> Inversion can be done with the <tt>recip</tt> command:
<ul>
<li> <span class="cmd">recip(a)</span></li>
</ul>
</li>
<li> We don't have to define a variable first. All the above commands could
be equivalently written as:
<ul>
<li> <span class="cmd">(11::ZMOD 14)+25</span></li>
<li> <span class="cmd">11::ZMOD 14*39</span></li>
<li> <span class="cmd">11::ZMOD 14^537</span></li>
<li> <span class="cmd">recip(11::ZMOD 14)</span></li>
</ul>
</li>
<li> If the modulus is a prime, then division (by non-zero values) is also
possible. Axiom provides the alternative construction
<tt>PrimeField</tt> or more simply <tt>PF</tt>. For example:
<ul>
<li> <span class="cmd">a:=7::PF 11</span></li>
</ul>
</li>
<li> All the above arithmetic operations of addition, subtraction,
multiplication and powers work, but now we also have inversion:
<ul>
<li> <span class="cmd">1/a</span></li>
</ul>
</li>
<li> Using any of the methods you like, test out Fermat's theorem for a large
prime <tt>p</tt> and an integer <tt>a</tt>.
</li>
<li> Euler's totient function is implemented with <tt>eulerPhi</tt>. Choose
a large integer <tt>n</tt>, a random <tt>a</tt> with
<tt>gcd(a,n)=1</tt> , and test Euler's theorem
</li>
</ul>
</body>
</html>
|