Cryptography Reference
In-Depth Information
encoding = rot[n]) , where string consists of characters with ASCII code
in the 1
..
255 range (so that the null character with ASCII code 0 is excluded) and
n is an integer in the 0
255 range. This variant is impractical because many of the
ASCII-8 characters are rarely used in texts and some of them are even non-printable.
..
The version of the Caesar cipher in the previous example has the inconvenience
of not allowing the user to select the alphabet except for the two variants men-
tioned. We are going to give another simple implementation that can be used with
any alphabet obtained as a subset of the characters in the ASCII 1
..
255 range.
At the same time, this will allow us to give a gentle introduction to some of the
Maple functions we will be using. This version also takes advantage of Maple's
package StringTools which contains many utilities for the manipulation of text
strings. Since we will often work with messages given as text strings (later we will
also use messages given as files), we will make extensive use throughout the topic
of some of the routines in this package and hence we recommend the reader to
look up StringTools in Maple's help and examine the functions and the code
examples given there.
As before, we first load the package StringTools . An alternative way to use
the functions in the package is to call them by means of their 'long form calling
sequence', which does not require the previous loading of the package. For example,
the function SearchText below (which searches for the position of a substring
within a text string) can be called by inputting StringTools:-SearchText .
> with(StringTools):
Next, we define the alphabet and assign its value to a global variable called
alphabet :
> alphabet := convert([$97..122], bytes);
"abcdefghijklmnopqrstuvwxyz"
Here we are using the English (lower case) alphabet, but any other alphabet,
given by a string consisting of distinct characters in the ASCII code, may be used.
The function convert is another extremely useful function inMaple's kernel that is
used to convert between different data formats and that wewill often use, for example,
to convert between different number bases. Here we have used another variant of the
convert function, namely, convert/bytes , which converts between strings
and lists of integers by mapping characters to their ASCII codes (and conversely)
and will also often be used in our examples.
Next we define two mutually inverse bijections between the alphabet and
Z n ,
where n is the alphabet length (in our example they particularize to bijections between
the English alphabet and
Z 26 ). The function code assigns to each alphabet letter its
corresponding residue class—represented as an integer in the 0
..
25 range—and the
function char is the inverse of code .
> code:= letter -> SearchText(letter,alphabet)-1:
char := i -> alphabet[i+1]:
Now, we define a global variable modulus to which we assign the alpha-
bet length (26 for the English alphabet) and define a cyclic shift modulo this
 
Search WWH ::




Custom Search