Introduction to Mathematical Cryptography
COMP 323
spring, sophomore year
Historical Ciphers
Caesar Ciphers
“Shift” with wraparound. A function from { a , b , … , z } → { A , B , … , Z } \{a, b, \dots, z\} \rightarrow \{A, B, \dots, Z\} { a , b , … , z } → { A , B , … , Z }
Attack: Try all twenty-six possible keys
Atbash
Reflection. a ↔ z a \leftrightarrow z a ↔ z , b ↔ y b \leftrightarrow y b ↔ y , etc.
Special case of affine cipher.
Encryption and decryption are identical.
Substitution Ciphers
Each letter is substituted by another (distinct) letter. 26 ! > 10 20 26! > {10}^{20} 2 6 ! > 1 0 2 0 ciphers in total.
Attack: frequency analysis
Vigenere Cipher
Keyword.
Security proportional to keyword length.
Attack:
Find the length k k k of the keyword
Kasiski Method: Look for repeated fragments. Occurrences separated by multiples of the key length.
Guess the Length
Every k k k -th letter will be a caesar cipher
IndCo ( s ) = 1 n ( n − 1 ) ∑ i = 0 25 F i ( F i − 1 ) ≈ 1 n 2 ∑ i = 0 25 F i 2 \textrm{IndCo}(s) = \frac{1}{n(n - 1)} \sum_{i = 0}^{25} F_i (F_i - 1) \approx \frac{1}{n^2} \sum_{i = 0}^{25} {F_i}^2 IndCo ( s ) = n ( n − 1 ) 1 ∑ i = 0 2 5 F i ( F i − 1 ) ≈ n 2 1 ∑ i = 0 2 5 F i 2
MutIndCo ( s , t ) = 1 n m ∑ i = 0 25 F i ( s ) F i ( t ) \textrm{MutIndCo}(s, t) = \frac{1}{nm} \sum_{i = 0}^{25} F_i(s) F_i(t) MutIndCo ( s , t ) = n m 1 ∑ i = 0 2 5 F i ( s ) F i ( t )
random text: IndCo ≈ 0.0385 \textrm{IndCo} \approx 0.0385 IndCo ≈ 0 . 0 3 8 5
english text: IndCo ≈ 0.0685 \textrm{IndCo} \approx 0.0685 IndCo ≈ 0 . 0 6 8 5
Modern Cryptography
Goal: immune to code-breaking without knowing the key
Hard mathematical problems:
DH: Given g g g and g x m o d ( m ) g^x \mod (m) g x m o d ( m ) , find x x x (discrete logarithm)
RSA: Given x x x and g x m o d ( m ) g^x \mod (m) g x m o d ( m ) , find g g g (root extraction)
Mathematical tools:
modular arithmetic
extended euclidean algorithm
fermat’s little theorem
Public-key cryptography:
public key: anyone can send encrypted messages to Alice
private key: only Alice can decrypt the messages
Euclid’s Algorithm
gcd ( a , b ) ⋅ l c m ( a , b ) = a b \gcd(a, b) \cdot lcm(a, b) = ab g cd( a , b ) ⋅ l c m ( a , b ) = a b
x = q y + r ⟹ gcd ( x , y ) = gcd ( y , r ) x = qy + r \implies \gcd(x, y) = \gcd(y, r) x = q y + r ⟹ g cd( x , y ) = g cd( y , r )
For all integers a , b a, b a , b , there exist integers x , y x, y x , y such that a x + b y = gcd ( a , b ) ax + by = \gcd(a, b) a x + b y = g cd( a , b ) .
n n n -th prime approx n ln n n \ln n n ln n
number of primes lt n n n n ln n \frac{n}{\ln n} l n n n
probability that a random number is prime approx 1 ln n \frac{1}{\ln n} l n n 1
Modular arithmetic
a = r m o d m ⟹ a = m q + r a = r \mod m \implies a = mq + r a = r m o d m ⟹ a = m q + r
Equivalence relation (reflexive, transitive).
associative
commutative
distributive
a = b m o d m ∧ c = d m o d m ⟹ a ± c = b ± d m o d m a = b \mod m \wedge c = d \mod m \implies a \pm c = b \pm d \mod m a = b m o d m ∧ c = d m o d m ⟹ a ± c = b ± d m o d m
a = b m o d m ∧ c = d m o d m ⟹ a c = b d m o d m a = b \mod m \wedge c = d \mod m \implies ac = bd \mod m a = b m o d m ∧ c = d m o d m ⟹ a c = b d m o d m
Chinese Remainder Theorem
Given:
M = m 1 … m r M = m_1 \dots m_r M = m 1 … m r where gcd ( m i , m j ) = 1 \gcd(m_i, m_j) = 1 g cd( m i , m j ) = 1
a 1 , … , a r a_1, \dots, a_r a 1 , … , a r where 0 ≤ a j < m j 0 \leq a_j < m_j 0 ≤ a j < m j
…there exists a unique integer a a a such that a ≡ m o d m j a \equiv \mod m_j a ≡ m o d m j for all 1 ≤ j ≤ r 1 \leq j \leq r 1 ≤ j ≤ r , 0 ≤ a < M 0 \leq a < M 0 ≤ a < M .
Fermat’s Little Theorem
When p p p is prime and gcd ( n , p ) = 1 \gcd(n, p) = 1 g cd( n , p ) = 1 :
n p − 1 ≡ 1 m o d p n^{p - 1} \equiv 1 \mod p
n p − 1 ≡ 1 m o d p
n p ≡ n m o d p n^p \equiv n \mod p
n p ≡ n m o d p
n p − n ≡ 0 m o d p n^p - n \equiv 0 \mod p
n p − n ≡ 0 m o d p
RSA
choose two large primes p p p and q q q
λ = ( p − 1 ) ( q − 1 ) \lambda = (p - 1)(q - 1) λ = ( p − 1 ) ( q − 1 )
choose e e e such that gcd ( e , λ ) = 1 \gcd(e, \lambda) = 1 g cd( e , λ ) = 1
d = e − 1 m o d λ d = e^{-1} \mod \lambda d = e − 1 m o d λ
e , p q e, pq e , p q is public; d d d is private.
encryption: m e m o d p q m^e \mod pq m e m o d p q where m m m is the message and 0 < m < p q 0 < m < pq 0 < m < p q
decryption: m ≡ ( m e ) d m o d p q m \equiv {(m^e)}^d \mod pq m ≡ ( m e ) d m o d p q
Diffie-Hellman
secure 2-way communication. one-to-one.
choose a large prime p p p and its primitive root g g g
g x ≡ h m o d p g^x \equiv h \mod p g x ≡ h m o d p , x = log g h x = \log_g h x = log g h where 0 ≤ x < p 0 \leq x < p 0 ≤ x < p
private keys: a a a , b b b
public keys: A = g a m o d p A = g^a \mod p A = g a m o d p , B = g b m o d p B = g^b \mod p B = g b m o d p
shared private key: k = B a = A b = g a b m o d p k = B^a = A^b = g^{ab} \mod p k = B a = A b = g a b m o d p
encryption: k m = g a b m m o d p km = g^{ab} m \mod p k m = g a b m m o d p
decryption:
k − 1 = ( g a b ) − 1 m o d p k^{-1} = {(g^{ab})}^{-1} \mod p k − 1 = ( g a b ) − 1 m o d p (extended euclidean algorithm)
m = k − 1 k m m = k^{-1} km m = k − 1 k m
attacks:
single decrypted message: k = ( k m ) m − 1 k = (km) m^{-1} k = ( k m ) m − 1
many encrypted messages: k m 1 , k m 2 , … km_1, km_2, \dots k m 1 , k m 2 , … . k = gcd ( k m 1 , k m 2 , … ) k = \gcd(km_1, km_2, \dots) k = g cd( k m 1 , k m 2 , … )
MITM: eve replaces g a g^a g a and g b g^b g b with g e g^e g e . eve knows the shared private key.
many-to-one.
k k k ephemeral key (else likely key can be found by calculating the gcd)
c 1 = g k m o d p c_1 = g^k \mod p c 1 = g k m o d p and c 2 = g k a m o d p c_2 = g^{ka} \mod p c 2 = g k a m o d p
( c 1 , c 2 ) (c_1, c_2) ( c 1 , c 2 )
decryption:
x = c 1 a = g k a m o d p x = c_1^a = g^{ka} \mod p x = c 1 a = g k a m o d p
find x − 1 m o d p x^{-1} \mod p x − 1 m o d p (extended euclidean algorithm)
Primitive Root Theorem: dots
Groups
G G G set, ∗ * ∗ binary op
identity: e ∗ g = g ∗ e = g e * g = g * e = g e ∗ g = g ∗ e = g
inverse: g − 1 ∗ g = g ∗ g − 1 = e g^{-1} * g = g * g^{-1} = e g − 1 ∗ g = g ∗ g − 1 = e
associative: a ∗ ( b ∗ c ) = ( a ∗ b ) ∗ c a * (b * c) = (a * b) * c a ∗ ( b ∗ c ) = ( a ∗ b ) ∗ c
(optional, abelian) commutative: a ∗ b = b ∗ a a * b = b * a a ∗ b = b ∗ a
theorems:
if G G G is a finite group, every element of G G G has finite order.
if g k = e g^k = e g k = e , o r d ( g ) ∣ k ord(g) \mid k o r d ( g ) ∣ k
o r d ( g ) ∣ ∣ G ∣ = o r d ( G ) ord(g) \mid |G| = ord(G) o r d ( g ) ∣ ∣ G ∣ = o r d ( G )
Asymptotic Complexity
lim n → ∞ f ( x ) g ( x ) < ∞ ⟹ f ∈ O ( g ) \lim_{n \rightarrow \infty} \frac{f(x)}{g(x)} < \infty \implies f \in O(g) lim n → ∞ g ( x ) f ( x ) < ∞ ⟹ f ∈ O ( g )
Breaking
Discrete Logarithm Problem for Arbitrary Groups
Group G G G , g ∈ G g \in G g ∈ G , order of G G G is N N N .
Brute force: compute g , g 2 , … , g N − 1 g, g^2, \dots, g^{N - 1} g , g 2 , … , g N − 1 . O ( N ) O(N) O ( N ) (exponential in the number of bits)
Shank’s Algorithm: O ( N log N ) O(\sqrt{N} \log N) O ( N log N )
n = 1 + ⌊ ( N ) ⌋ n = 1 + \lfloor\sqrt(N)\rfloor n = 1 + ⌊ ( N ) ⌋
Create two lists of size N N N
baby steps: e , g , g 2 , … , g n e, g, g^2, \dots, g^n e , g , g 2 , … , g n
giant steps: h , h g − n , h g − 2 n , … , h g − n 2 h, hg^{-n}, hg^{-2n}, \dots, hg^{-n^2} h , h g − n , h g − 2 n , … , h g − n 2
Find a match between the two lists: g i = h g − j n g^i = hg^{-jn} g i = h g − j n
x = i + j n x = i + jn x = i + j n is a solution to g x = h g^x = h g x = h
Pohlig-Hellman Theorem
If we have an algorithm that takes O ( S q e ) O(S_{q^e}) O ( S q e ) steps to solve the DLP g x = h g^x = h g x = h in a group G G G for any element with o r d e r ( g ) = q e order(g) = q^e o r d e r ( g ) = q e where q q q is prime. We can solve
Miller-Rabin Test
Polynomials
Fundamental Theorem of Algebra : every polynomial of degree n n n has exactly n n n roots (possibly multiple and complex).
Bezout’s Theorem : suppose two polynomials F ( x , y ) F(x, y) F ( x , y ) and G ( x , y ) G(x, y) G ( x , y ) of degrees m m m and n n n respectively have no trivial factors. Then, { F ( x , y ) = 0 } ∩ { G ( x , y ) = 0 } \{F(x, y) = 0\} \cap \{G(x, y) = 0\} { F ( x , y ) = 0 } ∩ { G ( x , y ) = 0 } has exactly m n mn m n points.
Homogenization: P ( x , y , w ) = ∑ 0 ≤ i + j ≤ n a i , j x i y j w n − i − j P(x, y, w) = \sum_{0 \leq i + j \leq n} a_{i, j} x^i y^j w^{n - i - j} P ( x , y , w ) = ∑ 0 ≤ i + j ≤ n a i , j x i y j w n − i − j
Dehomogenization: P ( x , y , 1 ) P(x, y, 1) P ( x , y , 1 )
w = 0 w = 0 w = 0 : points at infinity
w = 1 w = 1 w = 1 : affine points
Note: ( 0 , 0 , 0 ) (0, 0, 0) ( 0 , 0 , 0 ) is not a point in the projective space.