Skip to main content

Discrete Mathematical Structures

Subsection 5.5.1 Shift ciphers

We want a method to encrypt, or make secret, a plain text message. One of the earliest know approaches was by Julius Caesar. The idea was to basically shift the alphabet by \(3\) spots.

Definition 5.5.1.1.

The Caesar cipher is the shift cipher, where we shift forward by three.
Here are the steps to encrypt using the Caesar cipher.
  1. Replace each letter in the message by an element of \(\ZZ_{26}\) equal to 1 less than its position in the alphabet. For example, A is replaced by \(0\text{,}\) B is replaced by \(1\text{,}\) \dots, Z is replaced by \(25\text{.}\) In this step, we are encoding
  2. Replace each number \(p\) by \((p + 3)\bmod 26\text{.}\) Equivalently, apply the function \(f \colon \ZZ_{26} \to \ZZ_{26}\) defined by \(f(x) = x + 3 \bmod 26\) to each number. This step does the encrypting.
  3. Translate the numbers back to letters.

Example 5.5.1.2.

Let’s encrypt CAT using the Caesar cipher.
First, we change CAT to numbers, we get 2 0 19. Apply \(f\) to get 5 3 22. Translate back to letters to get FDW.
\begin{align*} \text{C}\amp\xrightarrow{\text{encode}} 2 \xrightarrow{\text{encrypt}} 5 \xrightarrow{\text{decode}} \text{F}\\ \text{A}\amp \xrightarrow{\text{encode}} 0 \xrightarrow{\text{encrypt}} 3 \xrightarrow{\text{decode}} \text{D}\\ \text{T}\amp \xrightarrow{\text{encode}} 19 \xrightarrow{\text{encrypt}} 22 \xrightarrow{\text{decode}} \text{W} \end{align*}
If we were going to encrypt longer messages, it would be faster to precompute a lookup table as shown in TableΒ 5.5.1.3.
Table 5.5.1.3.
A B C D E F G H I J K L M
D E F G H I J K L M N O P
N O P Q R S T U V W X Y Z
Q R S T U V W X Y Z A B C

Remark 5.5.1.4.

Instead of using \(f\text{,}\) which represents a shift of \(3\text{,}\) we can shift by any integer amount
\begin{equation*} f(x) = (x + k) \bmod{26} \end{equation*}
to yield a cipher known as a shift cipher . To decode, we use a function
\begin{equation*} g(x) = f^{-1}(x) = x - k \bmod{26}. \end{equation*}
More generally, the encryption function \(f\) can be any invertible function \(f \colon \ZZ_{26} \to \ZZ_{26}\text{.}\)
Figure 5.5.1.5. Privacy Opinions. (https://xkcd.com/1269/) I’m the Philosopher until someone hands me a burrito.