B.2 Some Commands – Introduction to Cryptography with Coding Theory, 3rd Edition

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


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×n matrix with first row a,b, ... and last row ...z. To multiply two matrices A and B,  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 ϕ(12345). 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 a^b. However, we will need to use modular exponentiation with very large exponents. In that case, use a&^bmodn. For modular exponentiation, you might need to use a between & and 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, y) and (u, v) on the elliptic curve y2x3+bx+c(modn). The integer n should be odd.

affinecrypt(txt,m,n) is the affine encryption of txt using mx+n.

allshifts(txt) gives all 26 shifts of txt.

chrem([a,b,...], [m,n,...]) gives a solution to the simultaneous congruences xa(modm), xb(modn), .

choose(txt,m,n) lists the characters in txt in positions that are congruent to n(modm).

coinc(txt,n) is the number of matches between txt and txt displaced by n.

corr(v) is the dot product of the vector v with the 26 shifts of the alphabet frequency vector.

phi(n) computes ϕ(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=gcd. To get x and y, type x;y on this or a subsequent command line.

ifactor(n) factors n.

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.

inverse(M) finds the inverse of the matrix M.

lfsr(c,k,n) gives the sequence of n bits produced by the recurrence that has coefficients given by the vector c. The initial values of the bits are given by the vector k.

lfsrlength(v,n) tests the vector v of bits to see if it is generated by a recurrence of length at most n.

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.

max(v) is the largest element of the list v.

a mod n is the value of a(modn).

multell([x,y], m, b, c, n) computes m times the point (x, y) on the elliptic curve y2x3+bx+c(modn).

multsell([x,y], m, b, c, n) lists the first m multiples of the point (x, y) on the elliptic curve y2x3+bx+c(modn).

nextprime(x) gives the next prime >x.

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.

shift(txt,n) shifts txt by n.

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(modm).