# B.2 Some Commands

The following are some Maple commands that are used in the examples. Some, such as `phi`

, are built into Maple. Others, such as `addell`

, are in the Maple notebook available at

`bit.ly/2TzKFec`

If you want to suppress the output, use a colon instead.

The argument of a function is enclosed in round parentheses. Vectors are enclosed in square brackets. Entering `matrix(m,n,[a,b,c,...,z])`

gives the $m\times n$ matrix with first row `a,b, ...`

and last row `...z`

. To multiply two matrices $A$ and $B\text{,}\text{}$ type `evalm(A&*B)`

.

If you want to refer to the previous output, use %. The next-to-last output is %%, etc. Note that % refers to the most recent output, not to the last displayed line. If you will be referring to an output frequently, it might be better to name it. For example, `g:=phi(12345)`

defines `g`

to be the value of $\varphi (12345)\text{.}$ Note that when you are assigning a value to a variable in this way, you should use a colon before the equality sign. Leaving out the colon is a common cause of hard-to-find errors.

Exponentiation is written as `$\text{a}^\text{b}\text{.}$`

However, we will need to use modular exponentiation with very large exponents. In that case, use `$\text{a\&}^\text{b}\text{\hspace{0.17em}}\text{mod}\text{\hspace{0.17em}}\text{n}\text{.}$`

For modular exponentiation, you might need to use a $\mathrm{\setminus}$ between & and `$\stackrel{\u02c6}{\phantom{a}}$`

. Use the right arrow to escape from the exponent.

Some of the following commands require certain Maple packages to be loaded via the commands

`with(numtheory), with(linalg), with(plots), with(combinat)`

These are loaded when the math.mws notebook is loaded. However, if you want to use a command such as `nextprime`

without loading the notebook, first type `with(numtheory):`

to load the package (once for the whole session). Then you can use functions such as `nextprime`

, `isprime`

, etc. If you type `with(numtheory)`

without the colon, you’ll get a list of the functions in the package, too.

The following are some of the commands used in the examples. We list them here for easy reference. To see how to use them, look at the examples. We have used `txt`

to refer to a string of letters. Such strings should be enclosed in quotes (`"string"`

).

`addell([x,y], [u,v], b, c, n)`

finds the sum of the points $(x\text{,}\text{}y)$ and $(u\text{,}\text{}v)$ on the elliptic curve ${y}^{2}\equiv {x}^{3}+bx+c\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{.}$ The integer $n$ should be odd.

`affinecrypt(txt,m,n)`

is the affine encryption of `txt`

using $mx+n\text{.}$

`allshifts(txt)`

gives all 26 shifts of `txt`

.

`chrem([a,b,...], [m,n,...])`

gives a solution to the simultaneous congruences $x\equiv a\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}m)\text{,}\text{}x\equiv b\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{,}\text{}\dots \text{\hspace{0.17em}}\text{.}$

`choose(txt,m,n)`

lists the characters in `txt`

in positions that are congruent to $n\phantom{\rule{negativethinmathspace}{0ex}}\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}m)\text{.}$

`coinc(txt,n)`

is the number of matches between `txt`

and `txt`

displaced by $n\text{.}$

`corr(v)`

is the dot product of the vector $v$ with the 26 shifts of the alphabet frequency vector.

`phi(n)`

computes $\varphi (n)$ (don’t try very large values of $n$).

`igcdex(m,n,’x’,’y’)`

computes the gcd of $m$ and $n$ along with a solution of $mx+ny=\mathrm{gcd}\text{.}$ To get `x`

and `y`

, type `x;y`

on this or a subsequent command line.

`ifactor(n)`

factors $n\text{.}$

`frequency(txt)`

lists the number of occurrences of each letter `a`

through `z`

in `txt`

.

`gcd(m,n)`

is the gcd of $m$ and $n\text{.}$

`inverse(M)`

finds the inverse of the matrix $M\text{.}$

`lfsr(c,k,n)`

gives the sequence of $n$ bits produced by the recurrence that has coefficients given by the vector $c\text{.}$ The initial values of the bits are given by the vector $k\text{.}$

`lfsrlength(v,n)`

tests the vector $v$ of bits to see if it is generated by a recurrence of length at most $n\text{.}$

`lfsrsolve(v,n)`

computes the coefficients of a recurrence, given a guess $n$ for the length of the recurrence that generates the binary vector $v\text{.}$

`max(v)`

is the largest element of the list $v\text{.}$

`a mod n`

is the value of $a\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{.}$

`multell([x,y], m, b, c, n)`

computes $m$ times the point $(x\text{,}\text{}y)$ on the elliptic curve ${y}^{2}\equiv {x}^{3}+bx+c\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{.}$

`multsell([x,y], m, b, c, n)`

lists the first $m$ multiples of the point $(x\text{,}\text{}y)$ on the elliptic curve ${y}^{2}\equiv {x}^{3}+bx+c\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{.}$

`nextprime(x)`

gives the next prime $>x\text{.}$

`num2text(n)`

changes a number $n$ to letters. The successive pairs of digits must each be at most 26 *space* is 00, $a$ is 01, $z$ is 26.

`primroot(p)`

finds a primitive root for the prime $p\text{.}$

`shift(txt,n)`

shifts `txt`

by $n\text{.}$

`text2num(txt)`

changes `txt`

to numbers, with `space=00, a=01, ..., z=25`

.

`vigenere(txt,v)`

gives the Vigenère encryption of `txt`

using the vector $v$ as the key.

`vigvec(txt,m,n)`

gives the frequencies of the letters `a`

through `z`

in positions congruent to $n\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}m)\text{.}$