Chapter 4
Chapter 4
Chapter 4
Abdelrahman Busati
College of Information Technology
University of Fujairah
4. Number Theory and
Cryptography
4.1.1 Introduction to Divisibility
and Modular Arithmetic
The ideas that we will develop in this section are based on the
notion of divisibility. Division of an integer by a positive integer
produces a quotient and a remainder. Working with these
remainders leads to modular arithmetic, which plays an
important role in mathematics and which is used throughout
computer science. We will discuss some important
applications of modular arithmetic later in this chapter,
4.1.2 Division
When one integer is divided by a second nonzero integer, the quotient
may or may not be an integer. For example, = 4 is an integer, whereas
= 2.75 is not. This leads to Definition 1.
Proof: We will give a direct proof of (i). Suppose that a ∣ b and a ∣ c. Then, from
the definition of divisibility, it follows that there are integers s and t with b = as
and c = at. Hence, b + c = as + at = a(s + t). Therefore, a divides b + c. This
establishes part (i) of the theorem. The proofs of parts (ii) and (iii) are left as
Exercises 3 and 4.
4.1.2 Division
Theorem 1 has this useful consequence.
Remark: Note that both a div d and a mod d for a fixed d are functions
on the set of integers. Furthermore, when a is an integer and d is a
positive integer, we have a div d = ⌊a∕d⌋ and a mod d = a − d.
4.1.3 The Division Algorithm
EXAMPLE 3: What are the quotient and remainder when 101 is divided
by 11?
Solution: We have
101 = 11 ⋅ 9 + 2.
Hence, the quotient when 101 is divided by 11 is 9 = 101 div 11, and
the remainder is
2 = 101 mod 11. ◂
4.1.3 The Division Algorithm
EXAMPLE 4: What are the quotient and remainder when −11 is
divided by 3?
Solution: We have −11 = 3(−4) + 1.
Hence, the quotient when −11 is divided by 3 is −4 = −11 div 3, and
the remainder is 1 = −11 mod 3.
Note that the remainder cannot be negative. Consequently, the
remainder is not −2, even though −11 = 3(−3) − 2,
because r = −2 does not satisfy 0 ≤ r < 3.
Note that the integer a is divisible by the integer d if and only if the
remainder is zero when a is divided by d
4.1.4 Modular Arithmetic
In some situations, we care only about the remainder of an integer
when it is divided by some specified positive integer. We have already
introduced the notation a mod m to represent the remainder when an
integer a is divided by the positive integer m. We now introduce a
different, but related, notation that indicates that two integers have the
same remainder when they are divided by the positive integer m.
4.1.4 Modular Arithmetic
Although both notations a ≡ b (mod m) and a mod m = b include “mod,”
they represent fundamentally different concepts. The first represents a
relation on the set of integers, whereas the second represents a function.
However, the relation a ≡ b (mod m) and the mod m function are closely
related, as described in Theorem 3.
4.1.4 Modular Arithmetic
EXAMPLE 5: Determine whether 17 is congruent to 5 modulo 6 and
whether 24 and 14 are congruent modulo 6.
Solution: Because 6 divides 17 − 5 = 12, we see that 17 ≡ 5 (mod 6).
However, because 24 − 14 = 10 is not divisible by 6, we see that 24 ≢ 14
(mod 6). ◂
4.2.1 Introduction Integer
Representations and Algorithms
Integers can be expressed using any integer greater than one as a base,
as we will show in this section. Although we commonly use decimal
(base 10), representations, binary (base 2), octal (base 8), and
hexadecimal (base 16) representations are often used, especially in
computer science.
We will also introduce an algorithm for finding a div d and a mod d
where a and d are integers with d > 1. Finally, we will describe an
efficient algorithm for modular exponentiation, which is a particularly
important algorithm for cryptography, as we will see in Section 4.6.
4.2.2 Representations of Integers
4.2.2 Representations of Integers
4.2.2 Representations of Integers
Theorem 1 is called the base b expansion of n. The base b
expansion of n is denoted by (akak−1 … a1a0)b. For instance, (245)8
represents 2 ⋅ 82 + 4 ⋅ 8 + 5 = 165. Typically, the subscript 10 is
omitted for base 10 expansions of integers because base 10, or
decimal expansions, are commonly used to represent integers.
BINARY EXPANSIONS Choosing 2 as the base gives binary
expansions of integers. In binary notation each digit is either a 0 or
a 1. In other words, the binary expansion of an integer is just a bit
string. Binary expansions (and related expansions that are variants
of binary expansions) are used by computers to represent and do
arithmetic with integers.
4.2.2 Representations of Integers
EXAMPLE 1: What is the decimal expansion of the integer that
has (1 0101 1111)2 as its binary expansion?
Solution: We have
(1 0101 1111)2 = 1 ⋅ 28 + 0 ⋅ 27 + 1 ⋅ 26 + 0 ⋅ 25 + 1 ⋅ 24 +1 ⋅ 23 + 1 ⋅
22 + 1 ⋅ 21 + 1 ⋅ 20 = 351.
•◂
OCTAL AND HEXADECIMAL EXPANSIONS Among the most
important bases in computer science are base 2, base 8, and
base 16. Base 8 expansions are called octal expansions and base
16 expansions are hexadecimal expansions.
4.2.2 Representations of Integers
EXAMPLE 2:
What is the decimal expansion of the number with octal expansion
(7016)8?
Solution:
Using the definition of a base b expansion with b = 8 tells us that
(7016)8 = 7 ⋅ 83 + 0 ⋅ 82 + 1 ⋅ 8 + 6 = 3598. ◂
4.2.2 Representations of Integers
Sixteen different digits are required for hexadecimal expansions.
Usually, the hexadecimal digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
C, D, E, and F, where the letters A through F represent the digits
corresponding to the numbers 10 through 15 (in decimal notation).