L03 – Division of residue classes, Euler’s phi function, Euler’s theorem, Fermat’s little theorem, and RSA

Discrete Mathematics2026年3月11日发布 芮和
3.3K 210
10,585字
45–67 分钟

Summary of Lecture 2

L02 – Equivalence, Congruence, and Residue Class

Binary relation: from AA to BB, RA×B={(a,b):aA,bB}R\subseteq A\times B=\left\{(a,b):\,a\in A,\,b\in B\right\}

Equivalence relation: a binary relation RR on a set AA. RA×AR\subseteq A\times A

  1. reflexive: aA,aRa\forall a\in A,\,aRa
  2. symmetric: a,bA,aRbbRa\forall a,b\in A,\,aRb\implies bRa
  3. transitive: a,b,cA,aRb,bRcaRc\forall a,b,c\in A,\,aRb,bRc\implies aRc
  • equivalence class [a]R={bA:aRb}[a]_R=\left\{b\in A:\,aRb\right\}
{[a]R=[b]R[a]R[b]R=\begin{cases}[a]_R=[b]_R\\[a]_R\cap[b]_R=\emptyset\end{cases}

Congruence: R={(a,b)2:n|(ab)}R = \left\{(a,b) \in \mathbb{Z}^2 :\,n\mid(a-b)\right\}

n+,Rn={(a,b):Rn×a,bn|(ab)}n\in\mathbb{Z}^+,\,R_n=\left\{(a,b):\,\substack{R_n\subseteq\mathbb{Z}\times\mathbb{Z}\\a\in\mathbb{Z},\,b\in\mathbb{Z}\\n\mid(a-b)}\right\}
aRnbaR_nb
ab(modn)a\equiv b\pmod{n}

  • 𝐚𝐛(mod𝐧):(a,b)R\mathbf{a \equiv b \pmod{n}}:\,(a,b) \in R
  • [a]n=a+n={a+nx:x}[a]_n = a + n\mathbb{Z} = \left\{a + nx :\,x \in \mathbb{Z}\right\}
  • a=nq+r:𝐚mod𝐧=𝐫a = nq + r:\,\mathbf{a} \bmod\mathbf{n = r}
  • [a]n[b]n=[a]_n \cap [b]_n = \emptyset or [a]n=[b]n[a]_n = [b]_n (iff ab(modn)a \equiv b \pmod{n})
  • n=[0]n,[1]n,,[n1]n\mathbb{Z}_n = {[0]_n, [1]_n, …, [n-1]_n}

(q,r)\exists(q,r) s.t. a=nq+r,0r<na=nq+r,\,0\leq r<n
[a]n=[r]n[a]_n=[r]_n
[a]nn=[0]n,[1]n,,[n1]n[a]_n\in\mathbb{Z}_n = {[0]_n, [1]_n, …, [n-1]_n}

Arithmetic operations over the setn={[0]n,[1]n,,[n1]n}\mathbb{Z}_n = \left\{[0]_n, [1]_n, …, [n-1]_n\right\}
partition

  • [a]n+[b]n=[a+b]n[a]_n + [b]_n = [a+b]_n
  • [a]n[b]n=[ab]n[a]_n – [b]_n = [a-b]_n
  • [a]n[b]n=[ab]n[a]_n \cdot [b]_n = [a \cdot b]_n//not an equality of sets

n\mathbb{Z}_n^*

[c]n=[a]n([b]n)1[c]_n=[a]_n\left([b]_n\right)^{-1}
[b]n=[a]n[s]n[b]_n=[a]_n\cdot [s]_n
[b]n[b]_n has an inverse [b]n[s]n=[1]n[b]_n[s]_n=[1]_n

DEFINITION: Let n+n \in \mathbb{Z}^+ and [b]nn[b]_n \in \mathbb{Z}_n. The residue class [s]nn[s]_n \in \mathbb{Z}_n is called an inverse of [b]n[b]_n if [b]n[s]n=[1]n[b]_n [s]_n = [1]_n.

  • The inverse of a residue class is unique (if exist). We denote ([b]n)1=[s]n\left([b]_n\right)^{-1} = [s]_n.
  • division: If [b]n[s]n=[1]n[b]_n [s]_n = [1]_n, define [a]n[b]n=[a]n([b]n)1=[a]n[s]n\frac{[a]_n}{[b]_n} = [a]_n \cdot \left([b]_n\right)^{-1} = [a]_n \cdot [s]_n

THEOREM: Let n+n \in \mathbb{Z}^+. [b]nn[b]_n \in \mathbb{Z}_n has an inverse if and only if gcd(b,n)=1\gcd(b, n) = 1.

  • Only if: s\exists s such that [b]n[s]n[1]n,[bs]n=[1]n,n|(bs1)[b]_n [s]_n \equiv [1]_n,\,[bs]_n=[1]_n,\,n\mid(bs-1);
    t,bs1=nt,d=gcd(b,n),d|bs,d|ntd|1,d=1\exists t, bs – 1 = nt,\,d=\gcd(b,n),\,\substack{d\mid bs,\,d\mid nt\\d\mid 1,\,d=1};
    gcd(b,n)=1\gcd(b, n) = 1
  • If: s,t\exists s, t such that bs+nt=1;bs1(modn)bs + nt = 1;\,bs \equiv 1 \pmod{n}
    [bs]n=[1]n,[b]n[s]n=[1]n[bs]_n=[1]_n,\,[b]_n[s]_n=[1]_n

DEFINITION: Let n+n \in \mathbb{Z}^+. Define n={[b]nn:gcd(b,n)=1}\mathbb{Z}_n^* = \set{[b]_n \in \mathbb{Z}_n :\,\gcd(b, n) = 1}.

  • If nn is prime, then n={1,2,,n1}\mathbb{Z}_n^* = \set{1, 2, \dots, n-1}
  • If nn is composite, then nn\mathbb{Z}_n^* \subset \mathbb{Z}_n

EXAMPLE:5={1,2,3,4};6={1,5};8={1,3,5,7}\mathbb{Z}_5^* = \set{1, 2, 3, 4};\,\mathbb{Z}_6^* = \set{1, 5};\,\mathbb{Z}_8^* = \set{1, 3, 5, 7}

n=5,{5={[0]5,[1]5,[2]5,[3]5,[4]5}5={[1]5,[2]5,[3]5,[4]5}n=5,\,\begin{cases}\mathbb{Z}_5=\left\{[0]_5,[1]_5,[2]_5,[3]_5,[4]_5\right\}\\\mathbb{Z}_5^*=\left\{[1]_5,[2]_5,[3]_5,[4]_5\right\}\end{cases}

Euler’s Phi Function

QUESTION: How many elements are there in n\mathbb{Z}_{n}^{*}

|n|\left|\mathbb{Z}_{n}^{*}\right| is the number of integers b[n]([n]={1,2,,n})b\in[n]\,\left([n]=\left\{1,2,\dots,n\right\}\right) such that gcd(b,n)=1\gcd(b,n)=1

DEFINITION (Euler’s Phi Function) ϕ(n)=|n|,n+\phi(n)=|\mathbb{Z}_{n}^{*}|,\,\forall n \in \mathbb{Z}^{+}.

  • ϕ(n)\phi(n) is the number of integers b[n]b \in[n] such that gcd(b,n)=1\gcd(b,n)=1
    //notation: [n]={1,2,,n}[n]=\left\{1,2,\dots,n\right\}
  • Gauss chose the symbol ϕ\phi for Euler’s Phi function

THEOREM: Let pp be a prime. Then e+,ϕ(pe)=pe1(p1)\forall\mathrm{e}\in\mathbb{Z}^{+},\,\phi\left(p^{e}\right)=p^{e-1}(p-1).

  • Let x{1,2,,pe}x \in\left\{1,2,\dots,p^{e}\right\}.
  • gcd(x,pe)1\gcd\left(x, p^{e}\right) \neq 1 iff p|xp\mid x
    gcd(x,pe)1\gcd\left(x, p^{e}\right) \neq 1 iff x=p,2p,,pe1px=p,2p,\dots,p^{e-1}\cdot p
    • ϕ(pe)=pepe1=pe1(p1)\phi\left(p^{e}\right)=p^{e}-p^{e-1}=p^{e-1}(p-1)

EXAMPLE: ϕ(32)=3(31)=6\phi\left(3^{2}\right)=3(3-1)=6

  • 9={1,2,4,5,7,8}\mathbb{Z}_{9}^{*}=\left\{1,2,4,5,7,8\right\}

EXAMPLE: ϕ(p)=p1\phi(p)=p-1

  • p={1,2,,p1}\mathbb{Z}_{p}^{*}=\left\{1,2, …, p-1\right\}

QUESTION: What is the formula of ϕ(n)\phi(n) for a general integer nn?

THEOREM: If n=p1e1prern=p_{1}^{e_{1}} \cdots p_{r}^{e_{r}} for distinct primes p1,,prp_{1},\dots,p_{r} and integers e1,,er1e_{1}, …, e_{r}\geq 1, then ϕ(n)=ϕ(p1e1)ϕ(prer)\phi(n)=\phi\left(p_{1}^{e_{1}}\right) \cdots \phi\left(p_{r}^{e_{r}}\right). Hence, ϕ(n)=n(1p11)(1pr1)\phi(n)=n\left(1-p_{1}^{-1}\right)\cdots\left(1-p_{r}^{-1}\right).

  • There are many proofs. We will see in the future.
    • Principle of inclusion-exclusion
    • Chinese remainder theorem

COROLLARY: If n=pqn=p q for two primes pqp\neq q, then ϕ(n)=(p1)(q1)\phi(n)=(p-1)(q-1).

EXAMPLE: ϕ(10)=(21)(51)=4;n=10;p=2,q=5\phi(10)=(2-1)(5-1)=4;\,n=10;\,p=2,\,q=5

  • 10={1,3,7,9}\mathbb{Z}_{10}^{*}=\left\{1,3,7,9\right\}

Euler’s Theorem

THEOREM (Euler, 1760) Let n1n\geq 1 and αn\alpha \in \mathbb{Z}_{n}^{*}. Then αϕ(n)=1\alpha^{\phi(n)}=1

[ax]n[ax]_n

{gcd(x,n)=1gcd(a,n)=1gcd(ax,n)=1\begin{cases}\gcd(x,n)=1\\\gcd(a,n)=1\end{cases}\implies\gcd(ax,n)=1

[x1]n[x2]n[xϕ(n)]n=[a]n[x1]n[a]n[x2]n[a]n[xϕ(n)]n\left[x_1\right]_n\cdot\left[x_2\right]_n\cdots\left[x_{\phi(n)}\right]_n=[a]_n\left[x_1\right]_n\cdot[a]_n\left[x_2\right]_n\cdots[a]_n\left[x_{\phi(n)}\right]_n

  • αϕ(n),1\alpha^{\phi(n)},1 are both residue classes modulo nn
  • Suppose that α=[a]n\alpha=[a]_{n} for aa \in \mathbb{Z}. Then αϕ(n)=1\alpha^{\phi(n)}=1 is ([a]n)ϕ(n)=[1]n\left([a]_{n}\right)^{\phi(n)}=[1]_{n}
  • How to prove?
    • Consider the map f:nn[x]n[a]n[x]nf:\,\mathbb{Z}_{n}^{*}\to\mathbb{Z}_{n}^{*}\quad[x]_{n}\mapsto[a]_{n} \cdot[x]_{n}
    • We show that ff is injective
      • f([x]n)=f([y]n)f\left([x]_{n}\right)=f\left([y]_{n}\right)
      • [a]n[x]n=[a]n[y]n[a]_{n} \cdot[x]_{n}=[a]_{n} \cdot[y]_{n}
      • [ax]n=[ay]n[a x]_{n}=[a y]_{n}
      • n|a(xy)n\mid a(x-y)
      • n|(xy)n\mid(x-y), this is because gcd(n,a)=1\gcd (n, a)=1
        • [x]n=[y]n[x]_{n}=[y]_{n}
    • Suppose that n={[x1]n,,[xϕ(n)]n}\mathbb{Z}_{n}^{*}=\left\{\left[x_{1}\right]_{n},\dots,\left[x_{\phi(n)}\right]_{n}\right\}
      • f([x1]n)f([xϕ(n)]n)=[x1]n[xϕ(n)]nf\left(\left[x_{1}\right]_{n}\right) \cdots f\left(\left[x_{\phi(n)}\right]_{n}\right)=\left[x_{1}\right]_{n} \cdots\left[x_{\phi(n)}\right]_{n}
      • [ax1]n[axϕ(n)]n=[x1]n[xϕ(n)]n\left[a x_{1}\right]_{n} \cdots\left[a x_{\phi(n)}\right]_{n}=\left[x_{1}\right]_{n} \cdots\left[x_{\phi(n)}\right]_{n}
      • [aϕ(n)x1xϕ(n)]n=[x1xϕ(n)]n\left[a^{\phi(n)} x_{1} \cdots x_{\phi(n)}\right]_{n}=\left[x_{1} \cdots x_{\phi(n)}\right]_{n}
        • n|(aϕ(n)1)x1xϕ(n)n\mid\left(a^{\phi(n)}-1\right) x_{1} \cdots x_{\phi(n)}
          • n|(aϕ(n)1)n\mid\left(a^{\phi(n)}-1\right), this is because gcd(n,x1xϕ(n))=1\gcd\left(n,x_1\cdots x_{\phi(n)}\right)=1
            • [aϕ(n)]n=[1]n\left[a^{\phi(n)}\right]_{n}=[1]_{n}, i. e., ([a]n)ϕ(n)=[1]n\left([a]_{n}\right)^{\phi(n)}=[1]_{n}

Equivalent form: Let n1n\geq 1. Then aϕ(n)1(modn)a^{\phi(n)} \equiv 1\pmod{n} for any integer a such that gcd(a,n)=1\gcd(a, n)=1


Fermat’s Little Theorem

EXAMPLE: Understand Euler’s theorem with 10={1,3,7,9}\mathbb{Z}_{10}^{*}=\{1,3,7,9\}.

  • n=10,ϕ(n)=4n=10,\,\phi(n)=4,
  • 141(mod10)([1]10)4=[1]101^{4} \equiv 1\pmod{10}\implies\left([1]_{10}\right)^{4}=[1]_{10}
  • 34=811(mod10)([3]10)4=[1]103^{4}=81 \equiv 1\pmod{10}\implies\left([3]_{10}\right)^{4}=[1]_{10}
  • 74=24011(mod10)([7]10)4=[1]107^{4}=2401 \equiv 1\pmod{10}\implies\left([7]_{10}\right)^{4}=[1]_{10}
  • 94=65611(mod10)([9]10)4=[1]109^{4}=6561 \equiv 1\pmod{10}\implies\left([9]_{10}\right)^{4}=[1]_{10}
    • Consider the map f:1010[x]n[9]n[x]nf:\,\mathbb{Z}_{10}^{*} \to \mathbb{Z}_{10}^{*} \quad[x]_{n} \mapsto[9]_{n} \cdot[x]_{n}
    • f([1]10)=[9]10[1]10=[9]10f\left([1]_{10}\right)=[9]_{10}\cdot [1]_{10}=[9]_{10};
      f([3]10)=[7]10f\left([3]_{10}\right)=[7]_{10};
      f([7]10)=[3]10f\left([7]_{10}\right)=[3]_{10},
      f([9]10)=[1]10f\left([9]_{10}\right)=[1]_{10}
    • ff is injective
    • f([1]10)f([3]10)f([7]10)f([9]10)=[9]10[7]10[3]10[1]10f\left([1]_{10}\right) f\left([3]_{10}\right) f\left([7]_{10}\right) f\left([9]_{10}\right)=[9]_{10}[7]_{10}[3]_{10}[1]_{10}

Fermat’s Little Theorem (Euler, 1736) If pp is a prime and αp\alpha \in \mathbb{Z}_{p}.Then αp=α\alpha^{p}=\alpha.

  • By Euler’s theorem, αp1=1(α[0]p)\alpha^{p-1}=1\,(\forall \alpha \neq[0]_{p})
    • αp=α\alpha^{p}=\alpha

Equivalent form: If pp is a prime, then apa(modp)a^{p} \equiv a\pmod{p} for any integer aa.


Cryptography

  • Confidentiality: The property that sensitive information is not disclosed to unauthorized individuals, entities, or processes.
    –FIPS 140-2

Private-Key Encryption

  • 𝐆𝐞𝐧,𝐄𝐧𝐜,𝐃𝐞𝐜\mathbf{Gen},\mathbf{Enc},\mathbf{Dec}: key generation, encryption, decryption
  • m,c,km,c,k: plaintext (message), ciphertext, secret key
  • ,𝒞\mathcal{M},\mathcal{C}: plaintext space, ciphertext space
  • Π=(𝐆𝐞𝐧,𝐄𝐧𝐜,𝐃𝐞𝐜)+,||>1\Pi=(\mathbf{Gen},\mathbf{Enc},\mathbf{Dec})+\mathcal{M},\,\left|\mathcal{M}\right|>1
    • Correctness: 𝐃𝐞𝐜(k,𝐄𝐧𝐜(k,m))=m\mathbf{Dec}\left(k,\mathbf{Enc}(k, m)\right)=m for any k,mk,m
    • Security: if kk is not known, it’s difficult to learn mm from cc

Public-Key Encryption

  • 𝐆𝐞𝐧,𝐄𝐧𝐜,𝐃𝐞𝐜\mathbf{Gen},\mathbf{Enc},\mathbf{Dec}: key generation, encryption, decryption
  • m,c,pk,skm,c,pk,sk: plaintext (message), ciphertext, public key, private key
  • ,𝒞\mathcal{M},\mathcal{C}: plaintext space, ciphertext space
  • Π=(𝐆𝐞𝐧,𝐄𝐧𝐜,𝐃𝐞𝐜)+,||>1\Pi=(\mathbf{Gen},\mathbf{Enc},\mathbf{Dec})+\mathcal{M},\,\left|\mathcal{M}\right|>1
    • Correctness: 𝐃𝐞𝐜(sk,𝐄𝐧𝐜(pk,m))=m\mathbf{Dec}\left(sk,\mathbf{Enc}(pk, m)\right)=m for any pk,sk,mpk,sk,m
    • Security: if sksk is not known, it’s difficult to learn mm from pk,cpk,c

RSA

CONSTRUCTION: Π=(𝐆𝐞𝐧,𝐄𝐧𝐜,𝐃𝐞𝐜)+\Pi=(\mathbf{Gen},\mathbf{Enc},\mathbf{Dec})+\mathcal{M}, the message space is ={m:0m<N,gcd(m,N)=1}\mathcal{M}=\left\{m:\,0 \leq m<N,\,\gcd(m, N)=1\right\}

  • (pk,sk)𝐆𝐞𝐧(1n)(pk, sk) \leftarrow\mathbf{Gen}\left(1^{n}\right)
    • choose two nn-bit primes pqp\neq q
    • N=pq;ϕ(N)=(p1)(q1)N=p q ;\,\phi(N)=(p-1)(q-1)
    • choose e,de,d s.t. 0e,d<ϕ(N)0\leq e,\,d<\phi(N),
      • gcd(e,ϕ(N))=1\gcd\left(e, \phi(N)\right)=1
      • d=e1modϕ(N)d=e^{-1}\bmod{\phi(N)}
    • output pk=(N,e),sk=(N,d)pk=(N, e),\,sk=(N, d)
  • c𝐄𝐧𝐜(pk,m)c \leftarrow\mathbf{Enc}(pk, m):
    • output c=memodNc=m^e\bmod{N}
      • 0c<N0\leq c<N
  • m𝐃𝐞𝐜(sk,c)m \leftarrow\mathbf{Dec}(sk, c):
    • output m=cdmodNm=c^d\bmod{N}
      • 0m<N0\leq m<N

? 𝐃𝐞𝐜(sk,𝐄𝐧𝐜(pk,m))=m\mathbf{Dec}(sk,\mathbf{Enc}(pk, m))=m

  • ed1(modϕ(N))e d \equiv 1\pmod{\phi(N)}
  • t\exists t \in \mathbb{Z} s.t. ed=1+tϕ(N)e d=1+t \cdot \phi(N)
  • [cd]N=([c]N)d\left[c^d\right]_N=\left([c]_N\right)^d
    • =([me]N)d=\left(\left[m^e\right]_N\right)^d
      =(([m]N)e)d=\left(\left([m]_N\right)^e\right)^d
      =([m]N)ed=\left([m]_N\right)^{ed}
      =([m]N)1+tϕ(N)=\left([m]_N\right)^{1+t\phi(N)}
      =[m]N([m]N)tϕ(N)=[m]_N\cdot\left([m]_N\right)^{t\phi(N)}
      =[m]N[1]N=[m]_N\cdot[1]_N
      =[m]N=[m]_N
  • m=cdmodnm=c^d\bmod{n}

RSA is correct!

1977, Rivest, Shamir and Adleman: A method for obtaining digital signatures and public-key cryptosystems. MIT/LCS/TM-82. (Turing Award 2002)

© 版权声明

相关文章