Linear Algebra Cryptography
Linear Algebra Cryptography
Linear Algebra Cryptography
✫ ✪
4 To decode, multiply each block by the inverse matrix D (mod p). Not a very secure cipher!
Cryptography is about encoding and decoding messages. Banks do this all the time
with financial information. Amazingly, modern algorithms can involve extremely deep
mathematics. “Elliptic curves” play a part in cryptography, as they did in the sensational
proof by Andrew Wiles of Fermat’s Last Theorem.
This section will not go that far! But it will be our first experience with finite fields and
finite vector spaces. The field for Rn contains all real numbers. The field for “modular
arithmetic” contains only p integers 0, 1, . . . , p − 1. There were infinitely many vectors in
Rn —now there will only be pn messages of length n in message space. The alphabet from
A to Z is finite (as in p = 26).
The codes in this section will be easily breakable—they are much too simple for prac-
tical security. The power of computers demands more complex cryptography, because that
power would quickly detect a small encoding matrix. But a matrix code (the Hill Cipher)
will allow us to see linear algebra at work in a new way.
All our calculations in encoding and decoding will be “mod p”. But the central con-
cepts of linear independence and bases and inverse matrices and determinants survive this
change. We will be doing “linear algebra with finite fields”. Here is the meaning of mod p :
Dividing y by 5 produces one of the five possible remainders x = 0, 1, 2, 3, 4. All the num-
bers 5, −5, 10, −10, . . . with no remainder are congruent to zero (mod 5). The numbers
y = 6, −4, 11, −9, . . . are all congruent to x = 1(mod 5).
We use the word congruent for the symbol ≡ and we call this “modular arithmetic”.
Every integer y produces one of the values x = 0, 1, 2, . . . , p − 1.
The theory is best if p is a prime number. With p = 26 letters from A to Z, we
unfortunately don’t start with a prime p. Cryptography can deal with this problem.
502 Chapter 10. Applications
Modular Arithmetic
Linear algebra is based on linear combinations of vectors. Now our vectors (x1 , . . . , xn )
are strings of integers limited to x = 0, 1, . . . , p−1. All calculations produce these integers
when we work “mod p”. This means: Every integer y outside that range is divided by p
and x is the remainder:
Conclusion: We can safely add and multiply modulo p. So we can take linear combinations.
This is the key operation in linear algebra. But can we divide ?
In the real number field, the inverse is 1/y (for any number except y = 0). This means:
We found another real number z so that yz = 1. Invertibility is a requirement for a field.
Is inversion always possible mod p ? For every number y = 1, . . . , p − 1 can we find
another number z = 1, . . . , p − 1 so that yz ≡ 1 mod p ?
The examples 3−1 ≡ 4 (mod 11) and 2−1 ≡ 6 (mod 11) and 5−1 ≡ 9 (mod 11) all
succeed. Can you solve 7z ≡ 1 (mod 11) ? Inverting numbers will be the key to inverting
matrices.
Let me show that inversion mod p has a problem when p is not a prime number. The
example p = 26 factors into 2 times 13. Then y = 2 cannot have an inverse z (mod 26).
The requirement 2z ≡ 1 (mod 26) is impossible to satisfy because 2z and 26 are even.
Similarly 5 has no inverse z when p is 25. We can’t solve 5z ≡ 1 (mod 25). The
number 5z − 1 is never going to be a multiple of 5, so it can’t be a multiple of 25.
By pure chance A−1 ≡ A ! Multiplying A times A mod 3 does give the identity matrix:
2 −1 2 0 2 0 4 0 1 0
A = AA = = ≡ (mod 3).
2 1 2 1 6 1 0 1
The determinant of A is 2, and the cofactor formula from Section 5.3 also gives A−1 ≡ A :
−1
2 0 1 −0 1 −0 2 0
= 2−1 ≡2 ≡ (mod 3).
2 1 −2 2 −2 2 2 1
Theorem. A−1 exists mod p if and only if (det A)−1 exists mod p.
The requirement is: det A and p have no common factors.
Of course a codebreaker will not know E or D. And the block size n is generally
unknown too. For the matrices Hill had in mind n would not be very large and a computer
could quickly discover E and D.
I am not sure if Hill’s Cipher could become seriously difficulty to break by choosing
very large matrices and a large prime number p. And by encoding the coded message a
second time, using a different block size n2 and large matrix E2 and large prime p2 .
course to be useful. I believe the right way is to understand Rn and its subspaces first,
as you do. Then you can look at other fields and vector spaces with a natural question
in mind: What is new when the field is not R ?
These pages are asking that question for finite fields. The possibilities become more
limited but also highly interesting. The starting point (and not quite the ending point) is
the finite field Fp . It contains only the numbers 0, 1, . . . , p − 1 and p is a prime number.
I will focus first on the field F2 with only 2 members “0” and “1”. You could think of 0
and 1 as “even” and “odd” because the rules to add and multiply are obeyed by the even
numbers and odd numbers: even + odd = odd and even × odd = even.
0 1 0 1
Addition 0 0 1 Multiplication 0 0 0
table 1 1 0 table 1 0 1
What are the possible bases for (F2 )3 ? The standard basis contains (1, 0, 0) and (0, 1, 0)
and (0, 0, 1). Those vectors are linearly independent and they span (F2 )3 . Their eight
combinations with coefficients 0 and 1 fill all of (F2 )3 .
What about matrices that multiply those vectors? The matrices will be 1 by 3, or 2 by
3, or 3 by 3. When they are 3 by 3 we can ask if they are invertible. Their determinants
can only be 0 (singular matrix) or 1 (invertible matrix). Let me leave you the pleasure of
deciding whether these matrices are invertible. And how would you find the inverse ?
1 0 0 1 1 0 1 1 1
A= 1 1 0 B= 0 1 1 C = 0 0 1
1 1 1 1 0 1 1 0 0
Out of 29 possible matrices over F2 , I will guess that most are singular.
To conclude this discussion of F2 , I mention a field with 22 = 4 members. It will not
come from multiplication (mod 4), because 4 is not prime. The multiplication 2 times 2
will give 0 (and 2 has no inverse): not a field. But we can start with the numbers 0 and 1
in F2 and invent two more numbers a and 1 + a—provided they follow these two rules:
(a + a = 0) and (a × a = 1 + a). Then a and 1 + a are inverses. Not obvious !
506 Chapter 10. Applications
Beyond p = 2, we have the fields Fp for all prime numbers p. They use addition and
multiplication mod p. They are alphabets for codes. They provide the components for
vectors v = (f1 , . . . , fn ) in the space (Fp )n . They provide the entries for matrices that
multiply those vectors. These fields Fp are the most frequently used finite fields.
The only other finite fields have pk members. The example above of 0, 1, a, 1 + a
had 22 = 4 members. We will leave it there and get back safely to R.