Introduction to Mathematica

Math 202 Cryptography, September 7, 2016
T. Ratliff, Wheaton College
ratliff_thomas@wheatoncollege.edu

A few basics

Mathematica commands begin with capital letters
Arguments are contained in square brackets [ ]
To execute a Mathematica command, press SHIFT-ENTER
For example, to graph y=cos(x) from x=0 to 2 π

Plot[ Cos[x], {x,0,2Pi}]

Or to find 15*11 mod 26

Mod[ 15*11, 26]

Shift ciphers

Let’s look at encrypting “E” using a shift cipher with k=7
LetterNumber[ ] returns the position of a letter in the alphabet

LetterNumber["E"]

Oops. Since we’re in Z_26, we want to start with “A” -> 0, so we should have “E” -> 4
We need to subtract one from the result of LetterNumber[ ]

x=LetterNumber["E"] - 1

To encrypt, y = x+k mod 26

y=Mod[x+7, 26]

We can put this all together in one group by entering just RETURN, not SHIFT-RETURN between the lines. You’ll need to use SHIFT-RETURN to execute.

x=LetterNumber["E"]-1
y=Mod[x+7,26]

If we receive y=3, we can decrypt by subtracting 7 and converting to a character

y=3
x=Mod[y-7,26]
FromLetterNumber[x+1]

Thus, we were sent “W”

Using lists

A really powerful feature of Mathematica is that it will also work with lists rather than just single values.
For example, we can encrypt multiple letters at the same time.

x=LetterNumber[{"M","E","E","T"}]-1
y=Mod[x+7,26]