Docsity

Modular Arithmetic & Algorithmic Number Theory in Algebraic Computing (CS 303) - Prof. Jer, Study notes of Computer Science

Partial preview of the text

Download Modular Arithmetic & Algorithmic Number Theory in Algebraic Computing (CS 303) - Prof. Jer and more Study notes Computer Science in PDF only on Docsity!

Algorithmic Number Theory and

Cryptography

(CS 303)

Modular Arithmetic Jeremy R. Johnson

Introduction

•^

Objective: To become familiar with modular arithmetic andsome key algorithmic constructions that are important forcomputer algebra algorithms.^ –^

Modular Arithmetic

-^

Modular inverses and the extended Euclidean algorithm

-^

Fermat’s theorem

-^

Euler’s Identity

-^

Chinese Remainder Theorem References: Rivest, Shamir, Adelman.

Modular Arithmetic (Z

)n

  • – [a] + [b] = [a+b] – [a] * [b] = [a*b] In order for this to make sense, you must get the same answer(equivalence) class independent of the choice of a and b. In otherwords, if you replace a and b by numbers equivalent to a or b mod n youend of with the sum/product being in the same equivalence class. a≡ It is possible to perform arithmetic with equivalence classesmod n.
    • a
    • ≡ (mod n) and b
    • b(mod n)
    • a+ b ⇒
    • ≡
    • a+ b
    • (mod n)
      • a* b
      • ≡
      • a* b
      • (mod n)
        • n) + (b + q (a + q
        • n) = a + b + (q
          • q
        • )n
          • n) * (b + q (a + q
          • n) = a * b + (b*q
            • a*q
            • q
            • q
          • )n

Representation of Z

n

The equivalence classes [a] mod n, are typically represented

by the representatives a.

-^

Positive Representation: Choose the smallest positiveinteger in the class [a] then the representation is {0,1,…,n-1}.

-^

Symmetric Representation: Choose the integer with thesmallest absolute value in the class [a]. The representationis {-

⎣(n-1)/

⎦^ ,…,

⎣n/

⎦^ }. When n is even, choose the

positive representative with absolute value n/2.

-^

E.G. Z
= {-2,-1,0,1,2,3}, Z 6

Fermat’s Theorem

Theorem: If a

≠^0
∈^

Z, then ap

p-^

≡^ 1 (mod p). More generally, if

a^ ∈

Zp

, then a

p^ ≡

a (mod p).

Proof: Assume that a

≠^0
∈^

Z. Thenp

a * 2a * … (p-1)a = (p-1)! * a

p-

Also, since a*i

≡^ a*j (mod p)

i^ ≡

j (mod p), the numbers

a, 2a, …, (p-1)a are distinct elements of Z

. Therefore theyp

are equal to 1,2,…,(p-1) and their product is equal to^ (p-1)! mod p. This implies that (p-1)! * a

p-^

≡^ (p-1)! (mod p)

p-1 a ≡^ 1 (mod p).

Euler phi function

•^

Definition: phi(n) = #{a: 0 < a < n and gcd(a,n) = 1}

-^

Properties:^ –^

ϕ(p) = p-1, for prime p.

-^

ϕ(p^e) = (p-1)*p^(e-1)

-^

ϕ^ (m*n) =

ϕ^ (m)*

ϕ(n) for gcd(m,n) = 1.

-^

ϕ(pq) = (p-1)(q-1)

-^

Examples:^ –^

ϕ(15) =

ϕ(3)*

ϕ(5) = 2*4 = 8. = #{1,2,4,7,8,11,13,14}

-^

ϕ(9) = (3-1)3^(2-1) = 23 = 6 = #{1,2,4,5,7,8}

Chinese Remainder Theorem

Theorem: If gcd(m,n) = 1, then given a and b there exist an

integer solution to the system: x^ ≡^

a (mod m) and x = b (mod n). Proof: Consider the map x

(x mod m, x mod n).

This map is a 1-1 map from Z

mn^

to Z

×m Zn

, since if x and y map

to the same pair, then x

≡^

y (mod m) and x

≡^

y (mod n).

Since gcd(m,n) = 1, this implies that x

≡^

y (mod mn).

Since there are mn elements in both Z

mn^

and Z

×m Zn

, the map

is also onto. This means that for every pair (a,b) we canfind the desired x.

Alternative Interpretation of CRT

•^

Let Z

×m Zn

denote the set of pairs (a,b) where a

∈^

Zm

a* b

Z. We can perform arithmetic on Zn

×m Zn

by performing

componentwise modular arithmetic.^ –^

(a,b) + (c,d) = (a+b,c+d)

-^

(a,b)(c,d) = (ac,b*d)

-^

Theorem: Z

mn^

≈^ Z

×m Zn

. I.E. There is a 1-1 mapping from

Zmn

onto Z

×m Zn

that preserves arithmetic.

-^

(ac mod m, bd mod n) = (a mod m, b mod n)*(c mod m, d mod n)

-^

(a+c mod m, b+d mod n) = (a mod m, b mod n)+(c mod m, d mod n)

-^

The CRT implies that the map is onto. I.E. for every pair (a,b) there isan integer x such that (x mod m, x mod n) = (a,b).