/usr/share/doc/axiom-doc/hypertex/cryptoclass2.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 222 | <?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 2: Strings and Values</h3>
</center>
<hr/>
<b>Characters and Strings</b>
<ul>
<li> All printable characters have a fixed ASCII value; some of which are:
<br/>
<pre>
Character | A B Y Z a b y z
------------+-------------------------------
ASCII Value | 65 66 89 90 97 98 121 122
|
Character | 0 1 8 9 , - . /
------------+-------------------------------
ASCII Value | 48 49 56 57 44 45 46 47
</pre>
</li>
<li> To obtain values 0 to 25 for A to Z, we need to subtract 65 from
the ASCII values.
</li>
<li> In Axiom, the <tt>ord</tt> command gives the ASCII value of a
character. Create a string such as:
<ul>
<li> <span class="cmd">str:="THISISASTRING"</span></li>
</ul>
</li>
<li> A string can be turned into a list of characters using <tt>members</tt>:
<ul>
<li> <span class="cmd">members(str)</span></li>
</ul>
</li>
<li> This means a string can be turned into a list of ASCII values by
mapping the <tt>ord</tt> function onto the list of members:
<ul>
<li> <span class="cmd">map(ord,members(str))</span></li>
</ul>
</li>
<li> To obtain values in the 0--25 range, try using an unnamed function:
<ul>
<li> <span class="cmd">strn:=map(x +-> ord(x)-65,members(str))</span></li>
</ul>
</li>
<li> Use this last command to create a function <tt>str2lst</tt> which will
take a string (assumed to be of capital letters, with no spaces or
punctuation), and return a list of values between 0 and 25.
</li>
<li> To go the other way, we first need to add 65 to all elements of
<tt>strn</tt>:
<ul>
<li> <span class="cmd">map(x +-> x+65,strn)</span></li>
</ul>
</li>
<li> Turn this into characters with <tt>char</tt>:
<ul>
<li> <span class="cmd">map(char,%)</span></li>
</ul>
</li>
<li> These can be done as a single command:
<ul>
<li> <span class="cmd">map(x +-> char(x+65),strn)</span></li>
</ul>
</li>
<li> To put them all together as a single string we can concatenate them
with the <tt>concat</tt> function from the <tt>String</tt> domain:
<ul>
<li> <span class="cmd">concat(%)$String</span></li>
</ul>
</li>
<li> In one line:
<ul>
<li> <span class="cmd">concat(map(x +-> char(x+65),strn))$String</span></li>
</ul>
</li>
<li> Alternatively, we could convert the characters to type <tt>String</tt>
before concatenation:
<ul>
<li>
<span class="cmd">
concat(map(x +-> char(x+65)::String,strn))
</span>
</li>
</ul>
</li>
<li> Use either version of this last command to create a function
<tt>lst2str</tt> which will take a list of values between 0 and 25 and
return a string.
</li>
<li> Create a text file in one of your private directories called
<tt>my3720.input</tt> and copy your <tt>str2lst</tt> and
<tt>lst2str</tt> functions to it.
</li>
<li> You can read command line input from a file with the extension
<tt>.input</tt> using the <tt>)read</tt> command:
<ul>
<li> <span class="cmd">)read my3720</span></li>
</ul>
</li>
<li> The Caesar cipher can be implemented by the following three steps:
<ol>
<li> Turn the string into a list,</li>
<li> Add 3 to every number in the list,</li>
<li> Turn this new list back into a string.</li>
</ol>
</li>
<li> To ensure that step (2) remains in the 0--25 range, we need to use the
<tt>rem</tt> function. These can all be put together as:
<ul>
<li>
<span class="cmd">
caesar(str) == lst2str(map(x +-> (x+3) rem 26, str2lst(str)))
</span>
</li>
</ul>
</li>
<li> Try this out on a few strings of your choice.</li>
<li> By replacing the "<tt>+3</tt>" in the <tt>caesar</tt> function with
"<tt>+n</tt>" create a new function called <tt>trans(str,n)</tt> which
implements a general translation cipher.
</li>
<li> Test it out; these two commands should produce the same results.
<ul>
<li> <span class="cmd">caesar("MYSTRING")</span></li>
<li> <span class="cmd">trans("MYSTRING",3)</span></li>
</ul>
</li>
<li> If you like, add the <tt>caesar</tt> and <tt>trans</tt> functions to
your <tt>my3720.input</tt> file.
</li>
<li> Test your <tt>trans</tt> function out on a few other strings and
translation values.
</li>
<li> The <tt>ROT13</tt> cipher is used in Usenet postings to hide information
which might be considered offensive. It is a translation cipher with a
shift of 13. Since 13 is half of 26, this means that encrytion and
decryption are exactly the same. Apply <tt>ROT13</tt> to:
<ul>
<li> GUVFVFNIRELFREVBHFOHFVARFF</li>
</ul>
</li>
<li> Consider this string which has been produced with a translation cipher.
To decrypt it, simply apply all possible shifts until you obtain
understandable text.
<ul>
<li> IUDTCUQBBOEKHCEDUO</li>
</ul>
</li>
<li> To apply all the possible shifts do:
<ol>
<li> <span class="cmd">ct:="IUDTCUQBBOEKHCEDUO"</span></li>
<li> <span class="cmd">for i in 1..26 repeat output trans(ct,i)</span></li>
</ol>
</li>
<li> What is the plaintext?</li>
</ul>
</body>
</html>
|