Crypto Maths - Part 1
Crypto Maths - Part 1
Crypto Maths - Part 1
Ashutosh Bhatia
BITS Pilani
[email protected]
Set of Integers and CRYPTO
The set of integers, denoted by Z, contains all integral numbers (with
no fraction) from negative infinity to positive infinity
𝑍 = . . . , −2, −1, 0, 1, 2, . . .
Euclidean Algorithm : gcd (a, 0) = a; gcd (a, b) = gcd (b, r), where r is the remainder of
dividing a by b
The extended Euclidean algorithm can calculate the gcd (a, b) and at the same time
calculate the value of s and t.
Euclidean Algorithm
• an efficient way to find the GCD(a,b)
EUCLID(a,b)
1. A = a; B = b
2. if B = 0 return A = gcd(a, b)
3. R = A mod B
4. A = B
5. B = R
6. goto 2
Example GCD(1970,1066)
1970 = 1 x 1066 + 904 gcd(1066, 904)
1066 = 1 x 904 + 162 gcd(904, 162)
904 = 5 x 162 + 94 gcd(162, 94)
162 = 1 x 94 + 68 gcd(94, 68)
94 = 1 x 68 + 26 gcd(68, 26)
68 = 2 x 26 + 16 gcd(26, 16)
26 = 1 x 16 + 10 gcd(16, 10)
16 = 1 x 10 + 6 gcd(10, 6)
10 = 1 x 6 + 4 gcd(6, 4)
6 = 1 x 4 + 2 gcd(4, 2)
4 = 2 x 2 + 0 ?????????
GCD
Modular Arithmetic
If 𝑎 = 𝑞𝑛 + 𝑟, then 𝑎 𝑚𝑜𝑑 𝑛 = ?
𝑎 𝑚𝑜𝑑 𝑛 is always an integer 𝑘 such that 0 ≤ 𝑘 ≤ 𝑛 − 1.
Hence, we can have arithmetic in the set of integers 0,1,2, … … 𝑛 − 1 in
which all arithmetic operators are modulo 𝑛.
Therefore, the result will always be in the set 0,1,2, … … 𝑛 − 1 .
The set 0,1,2, … … 𝑛 − 1 is referred as residue modulo 𝑛 and it is denoted
by 𝑍𝑛 .
Modular Arithmetic: Properties
1. a + b mod n = a mod n + b mod n mod n
2. a − b mod n = a mod n − b mod n mod n
3. ab mod n = a mod n ) (b mod n mod n (𝐻𝑜𝑚𝑒𝑤𝑜𝑟𝑘)
4. Commutative, Associate, Distributive
5. Identities
1. 0 + 𝑎 𝑚𝑜𝑑 𝑛 = 𝑎 𝑚𝑜𝑑 𝑛
2. 1 ∗ 𝑎 𝑚𝑜𝑑 𝑛 = 𝑎 𝑚𝑜𝑑 𝑛
Congruent Modulo Operator (≡)
An integer 𝑎 is congruent to and integer 𝑏 modulo 𝑛, denoted by
Additive Inverse:
𝑎, 𝑏 ∈ 𝑍𝑛, , then 𝑏 would be the additive inverse of 𝑎 if 𝑎 + 𝑏 𝑚𝑜𝑑 𝑛 = 0.
denoted as −𝑎
𝑎 + 𝑏 ≡ 0 𝑚𝑜𝑑 𝑛
In modular arithmetic ∀𝑎 ∈ 𝑍𝑛 , ∃ − 𝑎 ∈ 𝑍𝑛 𝑠. 𝑡. 𝑎 + 𝑏 𝑚𝑜𝑑 𝑛 = 0.
Find all additive inverse pairs in 𝑍8 .
Multiplicative Inverse:
𝑎, 𝑏 ∈ 𝑍𝑛, , then 𝑏 would be the multiplicative inverse of 𝑎 if 𝑎 ∗ 𝑏 𝑚𝑜𝑑 𝑛 = 1.
denoted as −𝑎
𝑎 ∗ 𝑏 ≡ 1 𝑚𝑜𝑑 𝑛
In modular arithmetic ~∀ 𝑎 ∈ 𝑍𝑛 , ∃ − 𝑎 ∈ 𝑍𝑛 𝑠. 𝑡. 𝑎 ∗ 𝑏 𝑚𝑜𝑑 𝑛 = 1.
Find all multiplicative inverse pairs in 𝑍8 .
Example: Addition Modulo 8
0 1 2 3 4 5 6 7
+
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 0
2 2 3 4 5 6 7 0 1
3 3 4 5 6 7 0 1 2
4 4 5 6 7 0 1 2 3
5 5 6 7 0 1 2 3 4
6 6 7 0 1 2 3 4 5
7 7 0 1 2 3 4 5 6