Cryptography is the study of secure communication techniques that allow only the sender and intended recipient of a message to view its contents.
Key Terminology:
Plaintext: The original, unencrypted message.
Ciphertext: The encrypted message.
Cipher: The algorithm used for encryption/decryption.
Enciphering (Encryption): Converting plaintext to ciphertext.
Deciphering (Decryption): Converting ciphertext to plaintext.
ECE Relevance:
Secure Communications: Protecting data in transit (e.g., wireless, internet).
Data Integrity: Ensuring messages haven’t been tampered with.
Authentication: Verifying identities.
Privacy: Securing personal and sensitive information.
Basic Ciphers: Substitution Ciphers
Substitution ciphers replace each letter of the alphabet with a different letter or symbol.
Example: Caesar Cipher (Shift Cipher)
Each letter is shifted a fixed number of positions down the alphabet.
Plain A becomes D, B becomes E, etc. (shift by 3).
Plaintext: ROME WAS NOT BUILT IN A DAY
Ciphertext: U RPH ZDV QRW EXLOW LQ D GDB
Weaknesses:
Frequency Analysis: They preserve the frequencies of individual letters.
Common letters like ‘E’, ‘T’, ‘A’ will still appear frequently, even if substituted.
This makes them relatively easy to break using statistical methods.
Caution
Substitution ciphers are generally not secure for modern applications!
Hill Ciphers: A Linear Algebra Approach
To overcome the weaknesses of substitution ciphers, polygraphic systems encipher groups of letters instead of single ones.
Polygraphic System: Divides plaintext into sets of \(n\) letters, which are then replaced by \(n\) cipher letters.
Hill Ciphers: A class of polygraphic systems using matrix transformations.
Introduced by Lester S. Hill in the 1920s.
Uses a square matrix (the encoding matrix) to transform numerical representations of plaintext letters into ciphertext.
Advantage: Conceals individual letter frequencies by mixing them within groups.
graph TD
A[Plaintext Message] --> B{Group into N-tuples}
B --> C[Convert Letters to Numbers]
C --> D[Plaintext Vector $\mathbf{p}$]
D -- Linear Transformation --> E[Multiply by Encoding Matrix A]
E --> F[Ciphertext Vector $\mathbf{c} = A\mathbf{p} \pmod{26}$]
F --> G[Convert Numbers to Letters]
G --> H[Ciphertext Message]
style A fill:#f9f,stroke:#333,stroke-width:2px
style H fill:#bbf,stroke:#333,stroke-width:2px
style E fill:#ccf,stroke:#333,stroke-width:2px
Encoding Scheme: Letters to Numbers
For Hill Ciphers, each letter of the alphabet is assigned a numerical value. We use a 0-indexed system for ‘Z’ to simplify modular arithmetic later.
Note
Convention: A=1, B=2, …, Y=25, Z=0.
Table 1: Alphabet to Numerical Values
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0
Hill Cipher Encoding Steps
Let’s formalize the encoding process for a Hill 2-cipher (using \(2 \times 2\) matrices).
Choose an Encoding Matrix \(A\):\[
A = \left[ \begin{array}{l l}{a_{11}} & {a_{12}}\\ {a_{21}} & {a_{22}} \end{array} \right]
\]
\(A\) must have integer entries.
Certain conditions on \(A\) are required for decipherment (we’ll see this later).
Group Plaintext Letters:
Divide the plaintext into successive pairs of letters.
If the plaintext has an odd number of letters, add a “dummy” letter (e.g., ‘Z’) to the last pair.
Convert to Vectors & Multiply:
Replace each plaintext letter by its numerical value (from Table 1).
Form a plaintext column vector \(\mathfrak{p} = \left[ \begin{smallmatrix} p_1 \\ p_2 \end{smallmatrix} \right]\).
Compute the ciphertext vector \(\mathfrak{c} = A\mathfrak{p}\).
Convert to Alphabetic Equivalent:
Transform the numerical entries of \(\mathfrak{c}\) back into letters using Table 1.
Example: Encoding “IAM HIDING”
Let’s use the encoding matrix \(A = \left[ \begin{smallmatrix} 1 & 2 \\ 0 & 3 \end{smallmatrix} \right]\) to encipher “IAM HIDING”.
Group Plaintext: IAM HIDING \(\rightarrow\) IA, MH, ID, IN, GG (added dummy ‘G’ for even pairs).
Enciphering MH:\[
\left[ \begin{array}{l l}{1} & {2}\\ {0} & {3} \end{array} \right] \left[ \begin{array}{l}{13}\\ {8} \end{array} \right] = \left[ \begin{array}{l}{1 \cdot 13 + 2 \cdot 8}\\ {0 \cdot 13 + 3 \cdot 8} \end{array} \right] = \left[ \begin{array}{l}{13 + 16}\\ {24} \end{array} \right] = \left[ \begin{array}{l}{29}\\ {24} \end{array} \right]
\]Problem: The number 29 has no alphabet equivalent (max is 25 for Y). Solution: We use modular arithmetic! Any number greater than 25 is replaced by its remainder after division by 26. \(29 \pmod{26} = 3\). So, \(\left[ \begin{smallmatrix} 3 \\ 24 \end{smallmatrix} \right]\). From Table 1: \(3 \rightarrow C\), \(24 \rightarrow X\). So, CX.
Modular Arithmetic: The Crypto Backbone
Modular arithmetic is fundamental to Hill Ciphers (and most modern cryptography).
Important
Definition: If \(m\) is a positive integer (the modulus), and \(a, b\) are any integers, then \(a\) is equivalent to \(b\) modulo \(m\), written \(a \equiv b \pmod{m}\), if \(a - b\) is an integer multiple of \(m\).
Examples of Equivalences:
\(7 \equiv 2 \pmod{5}\) (because \(7 - 2 = 5\), which is \(1 \cdot 5\))
\(19 \equiv 3 \pmod{2}\) (because \(19 - 3 = 16\), which is \(8 \cdot 2\))
\(-1 \equiv 25 \pmod{26}\) (because \(-1 - 25 = -26\), which is \(-1 \cdot 26\))
\(12 \equiv 0 \pmod{4}\) (because \(12 - 0 = 12\), which is \(3 \cdot 4\))
For any modulus \(m\), every integer \(a\) is equivalent to exactly one integer in the set \(Z_m = \{0, 1, 2, \ldots, m-1\}\). This integer is called the residue of \(a\) modulo \(m\).
Finding Residues (Interactive)
The residue of a non-negative integer \(a\) modulo \(m\) is simply the remainder when \(a\) is divided by \(m\). For negative integers, a theorem helps:
Tip
Theorem 10.14.1: For any integer \(a\) and modulus \(m\), let \(R = \text{remainder of } \frac{|a|}{m}\). Then the residue \(r\) of \(a\) modulo \(m\) is: \[
r = \left\{ \begin{array}{l l}{R} & {i f a \geq 0}\\ {m - R} & {i f a < 0 \text{ and } R \neq 0}\\ 0 & {i f a < 0 \text{ and } R = 0} \end{array} \right.
\]
Play with the inputs to see how residues are calculated.
viewof num_input = Inputs.text({label:"Enter an integer (a)",value:"87"});viewof mod_input = Inputs.text({label:"Enter a modulus (m)",value:"26"});
Multiplicative Inverses Modulo m
In ordinary arithmetic, every non-zero number \(a\) has a reciprocal \(a^{-1}\) such that \(a \cdot a^{-1} = 1\). In modular arithmetic, we seek \(a^{-1} \in Z_m\) such that \(a \cdot a^{-1} \equiv 1 \pmod{m}\).
Tip
A number \(a\) has a unique reciprocal modulo \(m\) if and only if \(a\) and \(m\) have no common prime factors (i.e., \(\text{gcd}(a, m) = 1\)).
Example 4: Reciprocal of 3 mod 26
\(\text{gcd}(3, 26) = 1\), so a reciprocal exists.
We need \(3x \equiv 1 \pmod{26}\).
By trying values from \(0\) to \(25\), we find \(x=9\), because \(3 \cdot 9 = 27 \equiv 1 \pmod{26}\).
Thus, \(3^{-1} \equiv 9 \pmod{26}\).
Example 5: A Number with No Reciprocal mod 26
The number \(4\) has no reciprocal modulo \(26\).
Why? Because \(4\) and \(26\) share a common prime factor: \(2\). (\(\text{gcd}(4, 26) = 2 \neq 1\)).
Multiplicative Inverses Modulo m (Interactive)
Test if a number has a reciprocal modulo \(m\), and find it if it exists.
To decode a Hill cipher, we need the inverse of the encoding matrix \(A\), denoted \(A^{-1}\), modulo \(m\).
If \(\mathbf{c} = A\mathbf{p} \pmod{m}\) is the ciphertext, then \(\mathbf{p} = A^{-1}\mathbf{c} \pmod{m}\) is the plaintext.
Important
Theorem 10.14.2: A square matrix \(A\) with entries in \(Z_m\) is invertible modulo \(m\) if and only if the residue of \(\det(A)\) modulo \(m\) has a reciprocal modulo \(m\).
Corollary 10.14.4 (for \(m=26\)):\(A\) is invertible modulo 26 if and only if the residue of \(\det(A)\) modulo 26 is not divisible by 2 or 13.
Inverse for a \(2 \times 2\) matrix (mod 26):
If \(A = \left[ \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \right]\), then \(A^{-1} = (\det(A))^{-1} \left[ \begin{smallmatrix} d & -b \\ -c & a \end{smallmatrix} \right] \pmod{26}\).
Where \((\det(A))^{-1}\) is the reciprocal of \(\det(A) = ad-bc\) modulo 26.
From Table 1: \(18 \rightarrow R\), \(9 \rightarrow I\). So, RI.
Continuing this process for all pairs yields: STRIKE NOWW.
Breaking the Code: Known Plaintext Attack
Cryptographers also study how to break ciphers (decipher without the key/matrix).
One method for Hill Ciphers is the Known Plaintext Attack.
Scenario: You intercept a ciphertext and have a guess about a small portion of the original plaintext (e.g., “DEAR”).
Tip
Theorem 10.14.5 (Determining the Deciphering Matrix):
For a Hill \(n\)-cipher, if you know \(n\) linearly independent plaintext vectors \(\mathbf{p}_1, \ldots, \mathbf{p}_n\) and their corresponding ciphertext vectors \(\mathbf{c}_1, \ldots, \mathbf{c}_n\), you can find the deciphering matrix \(A^{-1}\).
Using this \(A^{-1}\) on the entire ciphertext IOSBTGXESPXHOPDE yields:
DE AR IK ES EN DT AN KS\(\rightarrow\)DEAR IKE SEND TANKS
Linear Algebra in ECE: Beyond Hill Ciphers
The principles seen in Hill Ciphers extend to many vital ECE applications.
1. Digital Signal Processing (DSP):
Transformations: Fourier Transforms (DFT, FFT) are linear transformations, essential for signal analysis, filtering, and compression.
Filtering: Convolution operations can be represented as matrix multiplications.
2. Error Correction Codes:
Coding Theory: Linear block codes (e.g., Hamming codes, Reed-Solomon codes) use finite field linear algebra to detect and correct errors in data transmission.
3. Control Systems:
State-Space Representation: Linear systems are modeled using matrices (A, B, C, D) to analyze stability, controllability, and observability.
4. Communications Systems:
MIMO (Multiple-Input, Multiple-Output): Uses matrix algebra for spatial multiplexing and beamforming to increase data rates and reliability in wireless communication.
Modulation/Demodulation: Can involve linear transformations of signals.
5. Computer Graphics and Vision:
Transformations: 2D/3D rotations, scaling, translations are represented by matrices.
Image Processing: Filters, edge detection, and feature extraction often involve matrix operations.
6. Machine Learning/AI:
Neural Networks: Core operations are matrix multiplications and vector additions.
Data Analysis: Principal Component Analysis (PCA) for dimensionality reduction relies on eigenvectors and eigenvalues.
Conclusion
Key Takeaways
Hill Ciphers leverage matrix multiplication and modular arithmetic for polygraphic encryption, improving security over simple substitution ciphers.
Modular Arithmetic is essential for keeping numerical results within a defined range, crucial for alphabet mapping.
Matrix Inverses Modulo m enable decipherment and require specific conditions on the determinant.
Known Plaintext Attacks demonstrate vulnerabilities, where linear algebra can be used for cryptanalysis.