Skip to main content

Section 6.1 Modular Arithmetic

Subsection 6.1.1 Lester S. Hill

Insert bio here ...

Subsection 6.1.2 Moduli

The cipher we will focus on here, Hill's Cipher, is an early example of a cipher based purely in the mathematics of number theory and algebra; the areas of mathematics which now dominate all of modern cryptography.

Number theory has a long and rich history with many fundamental results dating all the way back to Euclid's Elements in 300 BCE, and with results found across the globe in different cultures. Number theory as we understand and use it today is due in large part to Carl Friedrich Gauss and his text Disquisitiones Arithmeticae published in 1801 (when Gauss was 24). Algebra (or more properly linear and abstract algebra) as it is going to be used here is much younger tracing its roots back only a couple hundred years to the early nineteenth century and the work of Cauchy and Galois.

As with previous topics we will begin by looking at an original source text when possible and trying to understand what it is saying. However, given the importance of this material to the rest of what we will be discussing in subsequent chapters, we will look at the material from a more modern perspective.

Cryptography in an Algebraic Alphabet.

By Lester S. Hill, Hunter College

1. The Bi-Operational Alphabet

Let \(a_0,\ a_1,\ \ldots,\ a_{25}\) denote any permutation of the letters of the English alphabet; and let us associate the letter \(a_i\) with the integer \(i\text{.}\) We define operations of modular addition and multiplication (modulo 26) over the alphabet as follows:

\begin{gather*} a_i+a_j=a_r,\\ a_i\, a_j=a_t, \end{gather*}

where \(r\) is the remainder obtained upon dividing the integer \(i+j\) by the integer 26 and \(t\) is the reaminder obtained on dividing \(ij\) by 26. The integers \(i\) and \(j\) may be the same or different.

It is easy to verify the following salient propositions concerning the bi-operational alphabet thus set up:

(1) If \(\alpha,\ \beta,\ \gamma\) are letters of the alphabet,

  • \(\alpha+\beta=\beta+\alpha\) and \(\alpha\beta=\beta\alpha\) [commutative law]
  • \(\alpha+(\beta+\gamma)=(\alpha+\beta)+\gamma\) and \(\alpha(\beta\gamma)=(\alpha\beta)\gamma\) [associative law]
  • \(\alpha(\beta+\gamma)=\alpha\beta+\alpha\gamma\) [distributive law]

(2) There is exactly one “zero” letter, namely \(a_0\text{,}\) characterized by the fact that the equation \(\alpha+a_0=\alpha\) is satisfied whatever the letter denoted by \(alpha\text{.}\)

(3) Given any letter \(\alpha\text{,}\) we can find exactly one letter \(\beta\text{,}\) dependent on \(\alpha\text{,}\) such that \(\alpha+\beta=a_0\text{.}\) We call \(\beta\) the “negative” of \(\alpha\text{,}\) and we write: \(\beta=-\alpha\text{.}\)

(4) Given any letters \(\alpha,\ \beta\) we can find exactly on letter \(\gamma\) such that \(\alpha+\gamma=\beta\) [i.e. \(\gamma=\beta-\alpha\) is unique].

(5) Distinguishing the twelve letters,

\begin{gather*} a_1,\ a_3,\ a_5,\ a_7,\ a_9,\ a_{11},\ a_{15},\ a_{17},\ a_{19},\ a_{21},\ a_{23},\ a_{25}, \end{gather*}

with subscripts prime to 26, as “primary” letters, we make the assertion, easily proved: If \(\alpha\) is any primary letter and \(\beta\) is any letter, there is exactly one letter \(\gamma\) for which \(\alpha\gamma=\beta\text{.}\)

(6) In any algebraic sum of terms, we may clearly omit terms of which the letter \(a_0\) is a factor; and we need not write the letter \(a_1\) explicitly as a factor in any product.

2. An Illustration

Let the letters of the alphabet be associated with the integers as follows:

Table 6.1.1.
a b c d e f g h i j k l m
5 23 2 20 10 1 8 4 18 25 0 16 13
n o p q r s t u v w x y z
7 3 1 19 6 12 24 21 17 14 22 11 9

or, in another convenient formulation:

0 1 2 3 4 5 6 7 8 9 10 11 12
k p c o h a r n g z e y s
13 14 15 16 17 18 19 20 21 22 23 24 25
m w f l v i q d u x b t j

It will be seen that

\begin{gather*} c+x=t,\ j+w=m,\ f+y=k,\ -f=y,\ -y=f,\ etc.\\ an=z,\ hm=k,\ cr=s,\ etc. \end{gather*}

The zero letter is \(k\text{,}\) and the unit letter is \(p\text{.}\) The primary letters are: \(a\) \(b\) \(f\) \(j\) \(n\) \(o\) \(p\) \(q\) \(u\) \(v\) \(y\) \(z\text{.}\)

Since this particular alphabet will be used several times, in illustration of further developments, we append the following table of negatives and reciprocals:

Letter : a b c d e f g h i j k l m n o p q r s t u v w x y z
Neg. : u o t r l y i x g p k e m q b j n d w c a z s h f v
Rec. : u v n j f z p y a b q o

The solution to the equation \(z+\alpha=t\) is \(\alpha=t-z\) or \(\alpha=t+(-z)=t+v=f\text{.}\)

The system of linear equations: \(o\, \alpha+u\, \beta = x\text{,}\) \(n\, \alpha+i\, \beta = q\) has solution \(\alpha = u\text{,}\) \(\beta=o\text{,}\) which may be obtained by the familiar method of elimination or by formula. [5, pp.306-308]

Comprehension Check:

  • Hill starts by describing how we will add and multiply with the alphabet, looking at his description why in his illustration does \(j+w\) which should be \(25+14=39\) (see Hill's Correspondence 6.1.1) come out to be \(m\) which is 13?
  • In his illustration he also says \(hm\) which should be 4 times 13, or 52, is \(k\) which is 0, why is this the case?
  • Along the same lines, why does \(f+y\) equal \(k\) and why does \(an\) (\(a\) times \(n\)) equal \(z\text{?}\)
  • Thinking about your previous answers, what are the values of the following: \(j+z\text{,}\) \(nf\text{,}\) \(au+j\text{,}\) and \(bv+jw\text{.}\)

In this section of text Hill has introduced us to the idea of modular arithmetic and modular equivalence, in particular the idea of equivalence modulo 26. This is a concept which will be central to most everything else we do so we need to spend a little more time trying to precisely understand modular equivalence.

Subsubsection 6.1.2.1 Modular Equivalence and Arithmetic

Definition 6.1.2. Modular Equivalence.

If \(n\) is a positive integer then we say that two other integers \(a\) and \(b\) are equivalent modulo n if and only if they have the same remainder when divided by \(n\text{,}\) or equivalently if and only if \(a-b\) is divisible by \(n\text{,}\) when this is the case we write

\begin{gather*} a\equiv b \pmod{n}. \end{gather*}

The number \(n\) is called the modulus.

Exploring Modular Arithmetic.

Suppose that \(n=14\text{,}\) then

\begin{equation*} 36\equiv 8\pmod{n} \end{equation*}

because

\begin{equation*} 36=2\cdot 14 + 8\ \text{and}\ 8=0\cdot (14) + 8 \end{equation*}

so we get the same remainder when we divide by \(n=14\text{.}\) Alternately, we can observe that \(36-8=28\) and \(28=2\cdot(14)\) is divisible by \(n=14\text{.}\)

Using the same value for \(n\) we say that \(3\cdot 5\equiv 1\pmod{n}\) because

\begin{equation*} 3\cdot 5=15=1\cdot (14) +1, \end{equation*}

that is the remainder when \(3\cdot 5\) is divided by \(n\) is 1.

Test your understanding by filling in the rest of this multiplication table:

Table 6.1.3. Multiplication Modulo 14
\(\times_{14}\) 0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 10 11 12 13
2 0 2 4 6 8 10 12 0 2 4
3 0 3 6 9 12 1 4 7 10 13 2 5 8 11
4 0 4 8 12 6 0
5 0 5 10 1 6 11
6 0 6 12 4 10 0
7 0 7 0 7
8 0
9 0
10 0
11 0
12 0
13 0

Comprehension Check:

  • What is strange or different about the row for 7? Why do you think all the remainders come out this way?
  • What is the difference between the even and odd rows (excluding row 7)?
  • For every number \(a\) is there always some number \(b\) so that \(ab=1\text{?}\)
  • Whenever \(ab=0\) is it always the case that either \(a=0\) or that \(b=0\text{?}\) Or, can you find examples where \(ab=0\) but \(a\neq 0\) and \(b\neq o\text{?}\)

Now try filling in this addition table for addition modulo 14.

Table 6.1.4. Addition Modulo 14
\(+_{14}\) 0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 0 1 2 3 4 5 6 7 8 9 10 11 12 13
1 1 2 3 4 5 6 7 8 9 10 11 12 13 0
2 2 3 4 5 6 7 8 9 10 11 12 13 0 1
3 3 4 5 6 7 8 9 10 11 12 13 0 1 2
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13

Comprehension Check:

  • For every number \(a\) is there always some number \(b\) so that \(a+b=0\text{?}\)
  • For every number \(a\) is there ever more than one number \(b\) so that \(a+b=0\text{?}\)

Now let's give some names to the observations that you hopefuly made.

Definition 6.1.5. Additive Identity.

We call 0 the additive identity because for all \(a\) and all possible moduli \(n\) we get

\begin{equation*} a+0\equiv a\pmod{n}\text{.} \end{equation*}
Definition 6.1.6. Additive Inverse.

We say that \(a\) and \(b\) are additive inverses modulo \(n\) if

\begin{equation*} a+ b\equiv 0 \pmod{n}, \end{equation*}

and we write \(b=-a\text{.}\)

Definition 6.1.7. Multiplicative Identity.

We call 1 the multiplicative identity because for all \(a\) and all possible moduli \(n\) we get

\begin{equation*} a\cdot 1\equiv a\pmod{n}\text{.} \end{equation*}
Definition 6.1.8. Multiplicative Inverse.

We say that \(a\) and \(b\) are multiplicative inverses modulo \(n\) if

\begin{equation*} a\cdot b\equiv 1 \pmod{n}, \end{equation*}

and we write \(b=a^{-1}\text{.}\)

Definition 6.1.9. Zero Divisor.

We say that \(a\) and \(b\) are zero divisors modulo \(n\) if \(a\neq 0\text{,}\) \(b\neq 0\text{,}\) and \(ab=0\text{.}\)

Comprehension Check:

  • Look back at the example of arithmetic modulo 14 and write down the pairs of additive and multiplicative inverses.
  • Do all the numbers modulo 14 have additive inverses?
  • Do all of them have multiplicative inverses?
  • Can you find pairs of numbers that are zero divisors?
  • If you compare your list of zero divisors with multiplicative inverses what do you notice?

Write down another multiplication and addition table as you did above for arithmetic modulo 14, but with a modulus of \(n=10\text{,}\) so when you multiply and add you will always divide by 10 afterwards and write down the remainder. After you write down the tables write down the pairs of multiplicative and additive inverses.

  • Do all the numbers modulo 10 have additive inverses?
  • Do all of them have multiplicative inverses?
  • Can you spot any zero divisors? How do they compare to your list of multiplicative inverses?

Write down another multiplication and addition table as you did above for arithmetic modulo 14, but with a modulus of \(n=12\text{,}\) so when you multiply and add you will always divide by 12 afterwards and write down the remainder. After you write down the tables write down the pairs of multiplicative and additive inverses.

  • Do all the numbers modulo 10 have additive inverses?
  • Do all of them have multiplicative inverses?
  • Can you spot any zero divisors? How do they compare to your list of multiplicative inverses?

Write down another multiplication and addition table as you did above for arithmetic modulo 14, but with a modulus of \(n=7\text{,}\) so when you multiply and add you will always divide by 7 afterwards and write down the remainder. After you write down the tables write down the pairs of multiplicative and additive inverses.

  • Do all the numbers modulo 10 have additive inverses?
  • Do all of them have multiplicative inverses?
  • Can you spot any zero divisors? How do they compare to your list of multiplicative inverses?

Comprehension Check: Look back at what Hill had to say and at the exercies you have worked through when you used moduli of \(n=14,10,12\) or \(7\) as you think about the following questions.

  • No matter which modulus you use, do all the numbers have additive inverses, i.e. numbers you can add to them in order to get 0?
  • No matter which modulus you use, do all the numbers have multiplicative inverses, i.e. numbers you can multiply them by in order to get 1?
  • If you look at the numbers which do have multiplicative inverses how do they relate to those which Hill described as prime to 26?
  • If you look at the numbers which are zero divisors how do they relate to those which Hill would describe as not prime to 26?
Definition 6.1.13. Relatively Prime.

We say that two integers are relatively prime if the largest positive integer which divideds them both, their greatest common divisor, is 1. For example the greatest common divisor of 7 and 36 is 1 so they are relatively prime, however the greatest common divisor of 30 and 36 is 6 so they are not relatively prime.

Which numbers, other than 7, that are less than 36 are relatively prime to 36?

Which numbers less than 14 are relatively prime to 14? How do these compare to the list of numbers which have multiplicative inverses? How do they compare to your list of zero divisors?

Which numbers less than 10 are relatively prime to 10? How do these compare to the list of numbers which have multiplicative inverses? How do they compare to your list of zero divisors?

Which numbers less than 26 are relatively prime to 26? How do these compare to the numbers which have multiplicative inverses? How do they compare to the zero divisors? (You will want to use Figure C.0.14.)

In the next section we are going to see how we can use these ideas to create a cipher. The cipher we create will be monoalphabetic, and so not very secure, but what will be important will be to focus on the math and how it can be used.