Discrete mathematics: cyroptology deals with finite objects (e.g. alphabets, blocks of characters)
Modular arithmetic; deals with finite number of values.
Z={…,−3,−2,−1,0,1,2,3,…} is the set of integers.
Given a,b∈Z, a divides b if there exists k∈Z such that ak=b. In this case, a is a factor of b: a∣b.
An integer p>1 is prime iff its only divisors are 1 and p.
If a∣b and a∣c, then a∣(b+c).
If p is prime and p∣ab, p∣a OR p∣b.
Given a,b∈Z such that a>b, then there exists q,r∈Z such that:
q is the quotient and 0≥r>b is the remainder. r<2a.
d is the GCD of a and b; gcd(a,b)=d if:
-
d∣a and ∣b
- If c∣a and c∣b, then c∣d
-
d>0
a and b are relatively prime if gcd(a,b)=1
To find d=gcd(a,b):
abr1rk−2rk−1=bq1+r1 for 0>r1>b=r1q2+r2 for 0>r2>r1=r2q3+r3 for 0>r3>r2…=rk−1qk+rk for 0>rk>rk−1=rkqk+1 with rk+1=0
Hence, d=rk=gcd(a,b).
In psuedo-code:
def gcd(a, b):
r[-1] = a
r[0] = b
k = 0
while r[k] != 0:
q[k] = floor(r[k - 1]/r[k])
r[r + 1] = r[k - 1] - q[k]r[k]
k = k + 1
k = k - 1
return r[k]
Find x, y in ax+by=d=rk.
rk−3=rk−2qk−1+rk−1
Can be rewritten as:
rk−1=rk−3−rk−2qk−1
rk−2=rk−1qk+rk can be rewritten as rk=rk−2−rk−1qk. rk−1 can be substituted with the value above. Hence, this process can be repeated until you have rk−1 in terms of the original values.
Example: gcd(17,3):
1732=3×5+2=2×1+1=1×2
Back-substitution:
1=3−2×1=3−(17−3×5)×1=17×−1+3×6
The result shows that 3−1≡6(mod17).
b is a residue of a(modn) if a−b=kn for some integer k:
a≡b(modn)⟺a−b=kn
Given a≡b(modn) and c≡d(modn):
a+cacka≡b+d(modn)≡bd(modn)≡kb(modn)
b(modn) denotes the unique value a in the complete set of residues {0,1,…,n−1} such that:
a≡b(modn)
In other words, b(modn) is the remainder after dividing a by n.
The set {r0,r1,…,rn−1} is a complete set of residues modulo n if for every a∈N, a≡ri(modn) for exactly one
ri.
The set {0,1,…,n−1} is denoted as Zn.
A group G is a set with binary operation ⋅ and:
- Closure: a⋅b∈G for any and all a,b∈G
- Identity: there is an element 1 such that a⋅1=1⋅a=a for any and all a∈G
- Inverse: there is an element b such that a⋅b=1 for any and all a∈G
- Associativity: (a⋅b)⋅c=a⋅(b⋅c) for any and all a,b,c∈G
A group is abelian when it is the operation is commutative; a⋅b=b⋅a for a,b∈G.
The order ∣G∣ of a group G is the number of elements in G.
gk denotes the repeated application of g∈G using the group operation. e.g. g3=g⋅g⋅g.
The order ∣g∣ of g∈G is the smallest integer k such that gk=1.
g is a generator for G if ∣g∣=∣G∣.
A group is cyclic if it has a generator.
The inverse if a (if it exists) is a value x such that ax≡1(modn); it is written as a−1(modn). This means that a must be coprime to n.
Theorem: let 0>a>n; a has an inverse modulo n iff gcd(a,n)=1.
The Euclidean algorithm can be used to find the inverse of a.
If x such that ax≡1(modn), there is an integer y such that ax=1+yn.
Hence, starting from gcd(a,n)=1, use back substitution to find x and y in the equation ax+ny=1. the y value gives the inverse.
Zp∗=1,2,…,p−1 is a complete set of residues modulo the prime p with the value 0 removed.
Properties:
-
∣Zp∗∣=p−1
-
Zp∗ is cyclic
-
Zp∗ has many generators (in general)
It can be thought of as the multiplicative group of integers 1,2,…,p−1 which have inverses modulo p.
A generator of Zp∗ is an element of order p−1
Lagrange theorem: the order of any element must exactly divide p−1.
To find a generator of Zp∗:
- Compute all distinct prime factors f1,f2,…,fr of p−1
-
g is a generator iff gfip−1=1(modp) for all i=1,2,…,r
Find a generator for Z11∗.
∣Z11∗∣ is 10 as 11 is prime. 10=2⋅5, so to check if g∈Z11∗ is a generator, check if g2≡1(mod11), g5≡1(mod11):
-
1: not a generator as 1n≡1(mod11)
-
2: 25≡32≡2≡1(mod11) and 22≡4≡1(mod11) so 2 is a generator
For any non-prime n, Zn∗ is a group of residues that have an inverse under multiplication.
Properties:
-
Zn∗ is a group
-
Zn∗ is not cyclic in general
- Finding its order is difficult
e.g. Z6∗={1,5} (elements coprime to 6).
Find a generator for Z9∗.
Z9∗={1,2,4,5,7,8,} so ∣Z9∗∣=6
-
1: not a generator as 1n≡1(mod9)
-
2:
-
22≡4(mod9)
-
23≡8(mod9)
-
24≡16≡7(mod9)
-
25≡32≡5(mod9)
-
26≡64≡1(mod9)
-
27≡128≡2(mod9)
- Hence, the order of 2 is equal to ∣Z9∗∣, cycling through all elements in the group before repeating
- NB: every element is guaranteed to be in Z9∗ as it is a group and hence has closure over the multiplication operation
A field F is a set with two binary operations, + and ⋅, with the properties such that:
-
F is an abelian group under the operation + with the identity element 0
-
F\{0} is an abelian group under the operation ⋅ with identity element 1
- Distributivity: a⋅(b+c)=(a⋅b)+(a⋅c) for a,b,c∈F
Theorem: only finite fields of size pn exist, where p is a prime and n is any positive integer.
For a finite field GF(p)=Zp:
- Multiplication and addition are done modulo p
- Its multiplicative group is exactly Zp∗
GF(2) is the simplest field with two elements, 0 and 1:
- Addition modulo 2: XOR (⊕)
- Multiplicative group: {1}
GF(28) is the field used for calculations in AES (block cipher).
Arithmetic in this field is considered as polynomial arithmetic where the field elements are polynomials with binary coefficients. e.g. 00101101↔x5+x3+x2+1
Properties:
- Polynomial division can be done easily using shift registers
- Adding two strings: add their coefficients modulo 2 (XOR)
- Multiplication with respect to a generator polynomial
- AES uses m(x)=x8+x4+x3+x+1
- Multiplying two strings: multiply them as polynomials, then take remainder of division by m(x)