arrow-left

All pages
gitbookPowered by GitBook
1 of 5

Loading...

Loading...

Loading...

Loading...

Loading...

Euler's Theorem in Detail

circle-info

Todo

Quadratic Residues

Fermat's Little Theorem in Detail

Would you like to be an author?

hashtag
Introduction

Since we can add, subtract, multiply, divide even... what would be missing? Powering! I'm not talking about some power fantasy here, but rather introduce some really really important theorems. Fermat little's theorem proves useful in a great deal of situation, and is along with Euler's theorem a piece of arithmetic you need to know. Arguably the most canonical example of using these is the RSA cryptosystem, whose decryption step is built around Euler's theorem.

hashtag
Fermat's Little Theorem

Since we want to talk about powers, let's look at powers. And because I like 7, I made a table of all the powers of all the integers modulo 7.

On the last row, there is a clear pattern emerging, what's going on??? Hm, let's try again modulo 5 this time.

Huh, again?! Clearly, there is something going on... Sage confirms this!

Claim (Fermat's Little Theorem): Leta prime.

When, this is equivalent to what we observed:. There are several proofs of Fermat's Little Theorem, but perhaps the fastest is to see it as a consequence of the Euler's Theorem which generalizes it. Still, let's look a bit at some applications of this before moving on.

A first funny thing is the following:. When, this means we have found a non-trivial integer that when multiplied toyields 1. That is, we have found the inverse of, wow. Since the inverse is unique modulo, we can always invert non-zero integers by doing this. From a human point of view, this is really easier than using the extended euclidean algorithm.

6

2

0

1

4

2

2

4

1

3

0

1

1

6

1

6

6

4

0

1

2

4

4

2

1

5

0

1

4

5

2

3

6

6

0

1

1

1

1

1

1

4

4

1

3

0

1

3

2

4

4

0

1

1

1

1

Power

0

1

2

3

4

5

6

1

0

1

2

3

4

Power

0

1

2

3

4

1

0

1

2

3

4

2

0

ppp
∀a∈Z,ap≡a [p]\forall a\in\mathbb Z, a^p\equiv a~[p]∀a∈Z,ap≡a [p]
a≠0a\neq 0a=0
ap−1≡1 [n]a^{p-1}\equiv 1~[n]ap−1≡1 [n]
∀a∈Z,a⋅ap−2≡ap−1≡1 [p]\forall a\in\mathbb Z, a\cdot a^{p-2}\equiv a^{p-1}\equiv 1~[p]∀a∈Z,a⋅ap−2≡ap−1≡1 [p]
p>2p>2p>2
aaa
aaa
ppp

5

1

p, itworks = 1, True
for _ in range(100):
    p = next_prime(p)
    Fp = GF(p) # Finite Field of size p
    itworks &= all(Fp(x)^(p-1) == 1 for x in range(1,p))

print(itworks)
# True

Modular Arithmetic

Authors: A~Z, perhaps someone else but not yet (or they've decided to remain hidden like a ninja)

hashtag
Introduction

Thinking not over the integers as a whole but modulo some integernnninstead can prove quite useful in a number of situation. This chapter attempts to introduce to you the basic concepts of working in such a context.

hashtag
Congruences

For the following chapter, we will assumeis a natural integer, andandare two integers. We say thatandare congruent modulowhen, or equivalently when there is an integersuch that. We denote this byor . I will use the first notation throughout this chapter.

Remark: When, we have, whereis the remainder in the euclidean division ofby

This relation has a number of useful properties:

Seeing as addition and multiplication are well defined, the integers moduloform a ring, which we note. In sage, you can construct such ring with either of the following

Powering modulois relatively fast, thanks to the algorithm, so we needn't worry about it taking too much time when working with high powers

As a side note, remember that if an equality holds over the integers, then it holds modulo any natural integer. This can be used to prove that a relation is never true by finding a suitable modulus, or to derive conditions on the potential solutions of the equation.

Example: by choosing an appropriate modulus, show that not even god is able to find integersandsuch that

hashtag
Modular Inverse

Since we can multiply, a question arises: can we divide? The answer is yes, under certain conditions. Dividing by an integeris the same as multiplying by its inverse; that is we want to find another integersuch that. Since, it is clear from that such an inverse exists if and only if. Therefore, the units moduloare the integers coprime to, lying in a set we call the unit group modulo:

Finding the modular inverse of a number is an easy task, thanks to the (that outputs solutions inandto the equationfrom above).

∀m∈N,a≡b [n]  ⟹  am≡bm [n]\forall m \in \mathbb N, a\equiv b~[n] \implies a^m\equiv b^m ~[n]∀m∈N,a≡b [n]⟹am≡bm [n]
  • The proofs are left as an exercise to the reader :p (Hint: go back to the definition)

  • nnn
    aaa
    bbb
    aaa
    bbb
    nnn
    n∣(b−a)n\mid (b-a)n∣(b−a)
    kkk
    a=b+kna=b+kna=b+kn
    a≡b [n]a\equiv b~ [n]a≡b [n]
    a≡bmod  na \equiv b\mod na≡bmodn
    b≠0b\neq0b=0
    a≡r [b]a\equiv r~[b]a≡r [b]
    rrr
    aaa
    ∀c∈Z,a≡b [n]  ⟹  ac≡bc [n]\forall c\in \mathbb Z, a\equiv b~[n] \implies ac \equiv bc ~ [n]∀c∈Z,a≡b [n]⟹ac≡bc [n]
    ∀c∈Z,a≡b [n]  ⟹  a+c≡b+c [n]\forall c \in \mathbb Z, a\equiv b~[n] \implies a+c\equiv b+c ~[n]∀c∈Z,a≡b [n]⟹a+c≡b+c [n]
    ∀c∈Z,a≡b [n] and b≡c [n]  ⟹  a≡c [n]\forall c \in \mathbb Z, a \equiv b ~[n] \text{ and } b\equiv c~[n]\implies a\equiv c ~[n]∀c∈Z,a≡b [n] and b≡c [n]⟹a≡c [n]
    nnn
    Z/nZ\mathbb Z/n\mathbb ZZ/nZ
    nnn
    nnn
    aaa
    bbb
    a2=2+4ba^2 = 2 + 4ba2=2+4b
    ccc
    ddd
    cd≡1 [n]cd\equiv 1~[n]cd≡1 [n]
    cd≡1 [n]  ⟺  ∃k∈Z,cd=1+kncd\equiv 1~[n]\iff\exists k\in\mathbb Z, cd = 1 + kncd≡1 [n]⟺∃k∈Z,cd=1+kn
    gcd⁡(c,n)=1\gcd(c, n) = 1gcd(c,n)=1
    nnn
    nnn
    nnn
    (Z/nZ)×\left(\mathbb Z/n\mathbb Z\right)^\times(Z/nZ)×
    ddd
    kkk
    cd−kn=1cd-kn=1cd−kn=1
    double-and-squarearrow-up-right
    Bézout's Identityarrow-up-right
    extended euclidean algorithmarrow-up-right
    Zn = Zmod(5)
    Zn = Integers(5)
    Zn = IntegerModRing(5)
    # Ring of integers modulo 5
    Zn(7)
    # 2
    Zn(8) == Zn(13)
    # True
    pow(2, 564654533, 7) # Output result as member of Z/7Z
    # 4
    power_mod(987654321, 987654321, 7) # Output result as simple integer
    # 6
    Zmod(7)(84564685)^(2^100) # ^ stands for powering in sage. To get XOR, use ^^.
    # 5
    Zn = Zmod(10)
    Zn(7).is_unit()
    # True
    Zn(8).is_unit()
    # False
    3 == 1/Zn(7) == Zn(7)^(-1) == pow(7,-1,10) # member of Z/10Z
    # True
    inverse_mod(7, 10) # simple integer
    # 3
    Zn(3)/7
    # 9
    Zn(3)/8
    # ZeroDivisionError: inverse of Mod(8, 10) does not exist
    Zn.unit_group()
    # Multiplicative Abelian group isomorphic to C4 (C4 being the cyclic group of order 4)
    xgcd(7, 10) # find (gcd(a, b), u, v) in au + bv = gcd(a, b)
    # (1, 3, -2) <-- (gcd(7, 10), d, -k)

    Theorems of Wilson, Euler, and Fermat

    hashtag
    Wilson's Theorem

    A positive integer n>1n > 1n>1is a prime if and only if:

    (n−1)!≡−1mod  n(n-1)! \equiv -1 \mod n (n−1)!≡−1modn

    hashtag
    Euler's Theorem

    Let and s.t. , then:

    hashtag
    Fermat's Little Theorem

    Let be a prime and , then:

    or equivalently:

    hashtag
    Reference

    n∈Z+n \in \mathbb{Z}^{+}n∈Z+
    a∈Za \in \mathbb{Z}a∈Z
    gcd(a,n)=1gcd(a, n) = 1gcd(a,n)=1
    aϕ(n)≡1mod  na^{\phi(n)} \equiv 1 \mod naϕ(n)≡1modn
    ppp
    a∈Za \in \mathbb{Z}a∈Z
    ap≡amod  pa^p \equiv a \mod pap≡amodp
    ap−1≡1mod  pa^{p-1} \equiv 1 \mod pap−1≡1modp
    Wilson's Theorem - Brilliantarrow-up-right
    Euler's Theorem - Brilliantarrow-up-right
    Fermat's Little Theorem - Brilliantarrow-up-right