2.2
To reviewinteger arithmetic, concentrating on divisibility
and finding the greatest common divisor using the Euclidean
algorithm
To understand how the extended Euclidean algorithm find
the multiplicative inverses
To emphasize the importance of modular arithmetic and
the modulo operator, because they are extensively used in
cryptography
Objectives
Chapter 2
3.
2.3
2-1 INTEGER ARITHMETIC
2-1INTEGER ARITHMETIC
In integer arithmetic, we use a set and a few
In integer arithmetic, we use a set and a few
operations. You are familiar with this set and the
operations. You are familiar with this set and the
corresponding operations, but they are reviewed here
corresponding operations, but they are reviewed here
to create a background for modular arithmetic.
to create a background for modular arithmetic.
2.1.1 Set of Integers
2.1.2 Binary Operations
2.1.3 Integer Division
2.1.4 Divisibility
Topics discussed in this section:
Topics discussed in this section:
4.
2.4
The set ofintegers, denoted by Z, contains all integral
numbers (with no fraction) from negative infinity to
positive infinity (Figure 2.1).
2.1.1 Set of Integers
Figure 2.1 The set of integers
5.
2.5
In cryptography, weare interested in three binary
operations applied to the set of integers. A binary
operation takes two inputs and creates one output.
2.1.2 Binary Operations
Figure 2.2 Three binary operations for the set of integers
6.
2.6
Example 2.1
2.1.2 Continued
Thefollowing shows the results of the three binary operations
The following shows the results of the three binary operations
on two integers. Because each input can be either positive or
on two integers. Because each input can be either positive or
negative, we can have four cases for each operation.
negative, we can have four cases for each operation.
7.
2.7
In integer arithmetic,if we divide a by n, we can get q
And r . The relationship between these four integers can
be shown as
2.1.3 Integer Division
a = q × n + r
8.
2.8
Assume that a= 255 and n = 11. We can find q = 23 and R = 2
using the division algorithm.
2.1.3 Continued
Figure 2.3 Example 2.2, finding the quotient and the remainder
Example 2.2
9.
2.9
2.1.3 Continued
Figure 2.4Division algorithm for integers
Two restrictions:
When we use the above division relationship in cryptography,
we impose the following two restriction.
Divisor be a positive integer (n>0)
Remainder be a non-negative integer (r>=0)
10.
2.10
Example 2.3
2.1.3 Continued
Whenwe use a computer or a calculator,
When we use a computer or a calculator, r
r and
and q
q are negative
are negative
when
when a
a is negative. How can we apply the restriction that
is negative. How can we apply the restriction that r
r
needs to be positive? The solution is simple, we decrement the
needs to be positive? The solution is simple, we decrement the
value of
value of q
q by 1 and we add the value of
by 1 and we add the value of n
n to
to r
r to make it
to make it
positive.
positive.
Example: if a=-255 and n=11
Example: if a=-255 and n=11
-255 = -253 – 2
-255 = -253 – 2 -255=-264 +9
-255=-264 +9
Example: if a=-127 and b=13
Example: if a=-127 and b=13
-127= 13 × -9 + (-10)
-127= 13 × -9 + (-10) -127 = -10 ×13 +3
-127 = -10 ×13 +3
11.
2.12
If a isnot zero and we let r = 0 in the division relation,
we get
2.1.4 Divisbility
a = q × n
If the remainder is zero,
If the remainder is not zero, a=255, n=23
n does not
divide a
a=255, n=5,
n divides a
n|a
n a
12.
2.13
Example 2.4
2.1.4 Continued
a.
a.The integer 4 divides the integer 32 because 32 = 8 × 4.
The integer 4 divides the integer 32 because 32 = 8 × 4.
We show this as
We show this as
b. The number 8 does not divide the number 42 because
b. The number 8 does not divide the number 42 because
42 = 5 × 8 + 2. There is a remainder, the number 2, in the
42 = 5 × 8 + 2. There is a remainder, the number 2, in the
equation. We show this as
equation. We show this as
2.15
Properties
2.1.4 Continued
Property 1:if a|1, then a = ±1.
Property 2: if a|b and b|a, then a = ±b.
Property 3: if a|b and b|c, then a|c.
Property 4: if a|b and a|c, then
a|(m × b + n × c), where m
and n are arbitrary integers
2.17
2.1.4 Continued
Fact 1:The integer 1 has only one
divisor, itself.
Fact 2: Any positive integer has at least
two divisors, 1 and itself (but it
can have more).
Note
2.19
Euclidean Algorithm
2.1.4 Continued
Fact1: gcd (a, 0) = a
Fact 2: gcd (a, b) = gcd (b, r), where r is
the remainder of dividing a by b
The greatest common divisor of two
positive integers is the largest integer
that can divide both integers.
Greatest Common Divisor
Note
Note
2.22
Example 2.7
2.1.4 Continued
Findthe greatest common divisor of 2740 and 1760.
Find the greatest common divisor of 2740 and 1760.
We have gcd (2740, 1760) = 20.
We have gcd (2740, 1760) = 20.
Solution
Solution
22.
2.23
Example 2.8
2.1.4 Continued
Findthe greatest common divisor of 25 and 60.
Find the greatest common divisor of 25 and 60.
We have gcd (25, 60) = 5.
We have gcd (25, 60) = 5.
Solution
Solution
23.
2.24
Extended Euclidean Algorithm
2.1.4Continued
Given two integers
Given two integers a
a and
and b
b, we often need to find other two
, we often need to find other two
integers,
integers, s
s and
and t
t, such that
, such that
The extended Euclidean algorithm can calculate the gcd (
The extended Euclidean algorithm can calculate the gcd (a
a,
, b
b)
)
and at the same time calculate the value of
and at the same time calculate the value of s
s and
and t
t.
.
24.
2.25
2.1.4 Continued
Figure 2.8.aExtended Euclidean algorithm, part a
The value of r, s and t are calculated using the following
The value of r, s and t are calculated using the following
formulas:
formulas:
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
The value of r, s and t are calculated using the following
The value of r, s and t are calculated using the following
formulas:
formulas:
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
2.27
Example 2.9
2.1.4 Continued
Given
Givena
a = 161 and
= 161 and b
b = 28, find gcd (
= 28, find gcd (a
a,
, b
b) and the values of
) and the values of s
s
and
and t
t.
.
We get gcd (161, 28) = 7,
We get gcd (161, 28) = 7, s
s = −1 and
= −1 and t
t = 6.
= 6.
Solution
Solution
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
27.
2.28
Example 2.10
2.1.4 Continued
Given
Givena
a = 17 and
= 17 and b
b = 0, find gcd (
= 0, find gcd (a
a,
, b
b) and the values of
) and the values of s
s
and
and t
t.
.
We get gcd (17, 0) = 17,
We get gcd (17, 0) = 17, s
s = 1, and
= 1, and t
t = 0
= 0.
.
Solution
Solution
28.
2.29
Example 2.11
2.1.4 Continued
Given
Givena
a = 0 and
= 0 and b
b = 45, find gcd (
= 45, find gcd (a
a,
, b
b) and the values of
) and the values of s
s
and
and t
t.
.
We get gcd (0, 45) = 45,
We get gcd (0, 45) = 45, s
s = 0, and
= 0, and t
t = 1.
= 1.
Solution
Solution
Assignment #1
Assignment #1
Question # 12, 13, 14, 15, 16
Question # 12, 13, 14, 15, 16
29.
2.30
2-2 MODULAR ARITHMETIC
2-2MODULAR ARITHMETIC
The division relationship (a = q × n + r) discussed in
The division relationship (a = q × n + r) discussed in
the previous section has two inputs (a and n) and two
the previous section has two inputs (a and n) and two
outputs (q and r). In modular arithmetic, we are
outputs (q and r). In modular arithmetic, we are
interested in only one of the outputs, the remainder r.
interested in only one of the outputs, the remainder r.
2.2.1 Modular Operator
2.2.2 Set of Residues
2.2.3 Congruence
2.2.4 Operations in Zn
2.2.5 Addition and Multiplication Tables
2.2.6 Different Sets
Topics discussed in this section:
Topics discussed in this section:
30.
2.31
The modulo operatoris shown as mod. The second input
(n) is called the modulus. The output r is called the
residue.
2.2.1 Modulo Operator
Figure 2.9 Division algorithm and modulo operator
31.
2.32
Example 2.14
2.1.4 Continued
Findthe result of the following operations:
Find the result of the following operations:
a.
a. 27 mod 5
27 mod 5 b.
b. 36 mod 12
36 mod 12
c.
c. −18 mod 14
−18 mod 14 d.
d. −7 mod 10
−7 mod 10
a.
a. Dividing 27 by 5 results in
Dividing 27 by 5 results in r
r = 2
= 2
b.
b. Dividing 36 by 12 results in
Dividing 36 by 12 results in r
r = 0.
= 0.
c. Dividing −18 by 14 results in
c. Dividing −18 by 14 results in r
r = −4. After adding the
= −4. After adding the
modulus
modulus r
r = 10
= 10
d. Dividing −7 by 10 results in r = −7. After adding the
d. Dividing −7 by 10 results in r = −7. After adding the
modulus to −7, r = 3.
modulus to −7, r = 3.
Solution
Solution
32.
2.33
The modulo operationcreates a set, which in modular
arithmetic is referred to as the set of least residues
modulo n, or Zn. It contains elements between 0 and n-1.
2.2.2 Set of Residues
Figure 2.10 Some Zn sets
33.
2.34
In cryptography, weoften used the concept of congruence
instead of equality.
To show that two integers are congruent, we use the
congruence operator ( ≡ ). For example, we write:
2.2.3 Congruence
2.36
A residue class[a] or [a]n is the set of integers congruent
modulo n.
if n is 5, then we we have the following residue classes
2.2.3 Continued
Residue Classes
2.38
Example 2.15
2.2.3 Continued
Weuse modular arithmetic in our daily life; for example, we
We use modular arithmetic in our daily life; for example, we
use a clock to measure time. Our clock system uses modulo 12
use a clock to measure time. Our clock system uses modulo 12
arithmetic. However, instead of a 0 we use the number 12.
arithmetic. However, instead of a 0 we use the number 12.
38.
2.39
The three binaryoperations that we discussed for the set
Z can also be defined for the set Zn. The result may need
to be mapped to Zn using the mod operator.
2.2.4 Operation in Zn
Figure 2.13 Binary operations in Zn
39.
2.40
Example 2.16
2.2.4 Continued
Performthe following operations (the inputs come from Zn):
Perform the following operations (the inputs come from Zn):
a. Add 7 to 14 in Z15.
a. Add 7 to 14 in Z15.
b. Subtract 11 from 7 in Z13.
b. Subtract 11 from 7 in Z13.
c. Multiply 11 by 7 in Z20.
c. Multiply 11 by 7 in Z20.
Solution
Solution
40.
2.41 19*64=1216
Example 2.17
2.2.4Continued
Perform the following operations (the inputs come from
Perform the following operations (the inputs come from
either Z or Z
either Z or Zn
n):
):
a. Add 17 to 27 in Z
a. Add 17 to 27 in Z14
14.
.
b. Subtract 43 from 12 in Z
b. Subtract 43 from 12 in Z13
13.
.
c. Multiply 123 by −10 in Z
c. Multiply 123 by −10 in Z19
19.
.
Solution
Solution
2.44
Example 2.18
2.2.4 Continued
Thefollowing shows the application of the above properties:
The following shows the application of the above properties:
1. (1,723,345 + 2,124,945) mod 11 = (8 + 9) mod 11 = 6
1. (1,723,345 + 2,124,945) mod 11 = (8 + 9) mod 11 = 6
2. (1,723,345 − 2,124,945) mod 16 = (8 − 9) mod 11 = 10
2. (1,723,345 − 2,124,945) mod 16 = (8 − 9) mod 11 = 10
3. (1,723,345 × 2,124,945) mod 16 = (8 × 9) mod 11 = 6
3. (1,723,345 × 2,124,945) mod 16 = (8 × 9) mod 11 = 6
44.
2.46
2.2.5 Inverses
When weare working in modular arithmetic, we often need
When we are working in modular arithmetic, we often need
to find the inverse of a number relative to an operation. We
to find the inverse of a number relative to an operation. We
are normally looking for an additive inverse (relative to an
are normally looking for an additive inverse (relative to an
addition operation) or a multiplicative inverse (relative to a
addition operation) or a multiplicative inverse (relative to a
multiplication operation).
multiplication operation).
45.
2.47
2.2.5 Continue
In Z
InZn
n, two numbers
, two numbers a
a and
and b
b are additive inverses of each
are additive inverses of each
other if
other if
Additive Inverse
In modular arithmetic, each integer has
an additive inverse. The sum of an
integer and its additive inverse is
congruent to 0 modulo n.
Note
46.
2.48
Example 2.21
2.2.5 Continued
Findall additive inverse pairs in Z10.
Find all additive inverse pairs in Z10.
Solution
Solution
The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7),
The six pairs of additive inverses are (0, 0), (1, 9), (2, 8), (3, 7),
(4, 6), and (5, 5).
(4, 6), and (5, 5).
47.
2.49
2.2.5 Continue
In Z
InZn
n, two numbers
, two numbers a
a and
and b
b are the multiplicative inverse of
are the multiplicative inverse of
each other if
each other if
Multiplicative Inverse
In modular arithmetic, an integer may or
may not have a multiplicative inverse.
When it does, the product of the integer
and its multiplicative inverse is
congruent to 1 modulo n.
Note
48.
2.50
Example 2.22
2.2.5 Continued
Findthe multiplicative inverse of 8 in Z
Find the multiplicative inverse of 8 in Z10
10.
.
Solution
Solution
There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1.
There is no multiplicative inverse because gcd (10, 8) = 2 ≠ 1.
In other words, we cannot find any number between 0 and 9
In other words, we cannot find any number between 0 and 9
such that when multiplied by 8, the result is congruent to 1.
such that when multiplied by 8, the result is congruent to 1.
Example 2.23
Find all multiplicative inverses in Z
Find all multiplicative inverses in Z10
10.
.
Solution
Solution
There are only three pairs: (1, 1), (3, 7) and (9, 9). The
There are only three pairs: (1, 1), (3, 7) and (9, 9). The
numbers 0, 2, 4, 5, 6, and 8 do not have a multiplicative
numbers 0, 2, 4, 5, 6, and 8 do not have a multiplicative
inverse.
inverse.
49.
2.51
Example 2.24
2.2.5 Continued
Findall multiplicative inverse pairs in Z
Find all multiplicative inverse pairs in Z11
11.
.
Solution
Solution
We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 5),
We have seven pairs: (1, 1), (2, 6), (3, 4), (5, 9), (7, 8), (9, 5),
and (10, 10).
and (10, 10).
50.
2.52
2.2.5 Continued
The extendedEuclidean algorithm finds
the multiplicative inverses of b in Zn
when n and b are given and
gcd (n, b) = 1.
The multiplicative inverse of b is the
value of t after being mapped to Zn.
Note
51.
2.53
Use extended Euclideanalgorithm to compute the gcd (n, b) if it
is 1 then the multiplicative inverse of b is the value of t in the
above EEA after being mapped to Zn.
Finding Multiplicative Inverse using
Extended Euclidean algorithm
a x s + b x t = gcd (a, b)
n x s + b x t = gcd (n, b)
[if a= n]
multInv of b exists only if gcd(n,b)=1
n x s + b x t = 1
Taking (mod n) on both sides of eqn
0 x s + (b x t) = 1 (modn)
52.
2.54
2.2.5 Continued
Figure 2.15Using extended Euclidean algorithm to
find multiplicative inverse
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
53.
2.55
Example 2.25
2.2.5 Continued
Findthe multiplicative inverse of 11 in Z
Find the multiplicative inverse of 11 in Z26
26.
.
Solution
Solution
The gcd (26, 11) is 1; the inverse of 11 is
The gcd (26, 11) is 1; the inverse of 11 is
7 or 19.
7 or 19.
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
54.
2.56
Example 2.26
2.2.5 Continued
Findthe multiplicative inverse of 23 in Z
Find the multiplicative inverse of 23 in Z100
100.
.
Solution
Solution
The gcd (100, 23) is 1; the inverse of 23 is
The gcd (100, 23) is 1; the inverse of 23 is
13 or 87.
13 or 87.
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
55.
2.57
Example 2.27
2.2.5 Continued
Findthe inverse of 12 in Z
Find the inverse of 12 in Z26
26.
.
Solution
Solution
The gcd (26, 12) is 2; the inverse does not exist.
The gcd (26, 12) is 2; the inverse does not exist.
r=r1-q×r2;
r=r1-q×r2;
s=s1-q×s2;
s=s1-q×s2;
t=t1-q×t2;
t=t1-q×t2;
where q represents the quotient of r1 and r2.
where q represents the quotient of r1 and r2.
56.
2.58
2.2.6 Addition andMultiplication Tables
Figure 2.16 Addition and multiplication table for Z10
57.
2.59
2.2.7 Different Sets
Figure2.17 Some Zn and Zn* sets
We need to use Zn when additive
inverses are needed; we need to use Zn*
when multiplicative inverses are needed.
Note
58.
Cryptographic Basic Terms
Plain Text : An original / intelligible message or data
Cipher text: coded message
Enciphering/Encryption: process of converting
plain text to cipher text
Deciphering/ Decryption: restoring the plain text
from the ciphertext
Key: the secret material used for performing
encryption/decryption
59.
Cryptographic Basic Terms
Plain Text : An original / intelligible message or data
Cipher text: coded message
Enciphering/Encryption: process of converting
plain text to cipher text
Deciphering/ Decryption: restoring the plain text
from the ciphertext
Key: the secret material used for performing
encryption/decryption
60.
Cryptographic Basic Terms
Cryptography: a word with Greek origins,
means “secret writing.”
Cryptanalysis: Techniques for deciphering
a message without any knowledge of
enciphering details.
Cryptology: Cryptography + Cryptanalysis
Steganography: “covered writing,” in
contrast with cryptography, which means
“secret writing.”
2.62
61.
Cryptographic Keys &
Additive& Multiplicative Inverses
If the operation (Encryption/ Decryption Algorithm)
is Addition, use additive inverse pairs in Zn as
Encryption/ Decryption keys.
If the operation (Encryption/ Decryption Algorithm)
is Multiplication use Multiplicative inverse pairs in
Zn* as Encryption/ Decryption keys.
Zp can provide Encryption/ Decryption key pairs for
both addition & multiplication algorithms.
Editor's Notes
#1 Now we will discuss the classical symmetric cryptography algorithm. Before discussing the classical algo, I will discuss few mathematical concepts used in classic algo.