๐ŸŽ‰ ไปŽ330่ฝฌไธบWashUๅธฎๅŠฉๆ‰‹ๅ†Œๅ•ฆ!

CSE442
ๆจกๅ—
Cse442t L9

Lecture 9

Continue on Cyclic groups

107662modโ€‰โ€‰51=(107modโ€‰โ€‰51)662modโ€‰โ€‰51=5662modโ€‰โ€‰51\begin{aligned} 107^{662}\mod 51&=(107\mod 51)^{662}\mod 51\\ &=5^{662}\mod 51 \end{aligned}

Remind that ฯ•(p),pโˆˆฮ ,ฯ•(p)=pโˆ’1\phi(p),p\in\Pi,\phi(p)=p-1.

51=3ร—17,ฯ•(51)=ฯ•(3)ร—ฯ•(17)=2ร—16=3251=3\times 17,\phi(51)=\phi(3)\times \phi(17)=2\times 16=32, So 532modโ€‰โ€‰15^{32}\mod 1

52โ‰ก25modโ€‰โ€‰51=255^2\equiv 25\mod 51=25
54โ‰ก(52)2โ‰ก(25)2modโ€‰โ€‰51โ‰ก625modโ€‰โ€‰51=135^4\equiv (5^2)^2\equiv(25)^2 \mod 51\equiv 625\mod 51=13
58โ‰ก(54)2โ‰ก(13)2modโ€‰โ€‰51โ‰ก169modโ€‰โ€‰51=165^8\equiv (5^4)^2\equiv(13)^2 \mod 51\equiv 169\mod 51=16
516โ‰ก(58)2โ‰ก(16)2modโ€‰โ€‰51โ‰ก256modโ€‰โ€‰51=15^16\equiv (5^8)^2\equiv(16)^2 \mod 51\equiv 256\mod 51=1

5662modโ€‰โ€‰51=107662modโ€‰โ€‰32modโ€‰โ€‰51=522modโ€‰โ€‰51=516โ‹…54โ‹…52modโ€‰โ€‰51=19\begin{aligned} 5^{662}\mod 51&=107^{662\mod 32}\mod 51\\ &=5^{22}\mod 51\\ &=5^{16}\cdot 5^4\cdot 5^2\mod 51\\ &=19 \end{aligned}

For aโˆˆZNโˆ—a\in \mathbb{Z}_N^*, the order of aa, o(a)o(a) is the smallest positive kk such that akโ‰ก1modโ€‰โ€‰Na^k\equiv 1\mod N. o(a)โ‰คฯ•(N),o(a)โˆฃฯ•(N)o(a)\leq \phi(N),o(a)|\phi (N)

In a general finite group

gโˆฃGโˆฃ=eg^{|G|}=e (identity)

o(g)โˆฃโˆฃGโˆฃo(g)\vert |G|

If a group G={a,a2,a3,...,e}G=\{a,a^2,a^3,...,e\} GG is cyclic

In a cyclic group, if o(a)=โˆฃGโˆฃo(a)=|G|, then a is a generator of GG.

Fact: Zpโˆ—\mathbb{Z}^*_p is cyclic

โˆฃZpโˆ—โˆฃ=pโˆ’1|\mathbb{Z}^*_p|=p-1, so โˆƒ\exists generator gg, and Z\mathbb{Z}, ฯ•(Z13โˆ—)=12\phi(\mathbb{Z}_{13}^*)=12

For example, 22 is a generator for Z13โˆ—\mathbb{Z}_{13}^* with 2,4,8,3,6,12,11,9,5,10,7,12,4,8,3,6,12,11,9,5,10,7,1.

If gg is a generator, f:Zpโˆ—โ†’Zpโˆ—f:\mathbb{Z}_p^*\to \mathbb{Z}_p^*, f(x)=gxmodโ€‰โ€‰pf(x)=g^x \mod p is onto.

What type of prime pp?

  • Large prime.
  • If pโˆ’1p-1 is very factorable, that is very bad.
    • Pohlig-Hellman algorithm
    • p=2n+1p=2^n+1 only need polynomial time to invert
  • We want p=2q+1p=2q+1, where qq is prime. (Sophie Germain primes, or safe primes)

There are probably infinitely many safe prime and efficient to sample as well.

If pp is safe, gg generator.

Zpโˆ—={g,g2,..,e}\mathbb{Z}_p^*=\{g,g^2,..,e\}

Then {g2,...g2q}Sg,pโŠ†Zpโˆ—\{g^2,...g^{2q}\}S_{g,p}\subseteq \mathbb{Z}_p^* is a subgroup; g2kโ‹…g2l=g2(k+l)โˆˆSg,pg^{2k}\cdot g^{2l}=g^{2(k+l)}\in S_{g,p}

It is cyclic with generator g2g^2.

It is easy to find a generator.

  • Pick aโˆˆZpโˆ—a\in \mathbb{Z}_p^*
  • Let x=a2x=a^2. If xโ‰ 1x\neq 1, it is a generator of subgroup SpS_p
    • Sp={x,x2,...,xq}modโ€‰โ€‰pS_p=\{x,x^2,...,x^q\}\mod p

Example: p=2โ‹…11+1=23p=2\cdot 11+1=23

we have a subgroup with generator 44 and S4={4,16,18,3,12,2,8,9,13,6,1}S_4=\{4,16,18,3,12,2,8,9,13,6,1\}

def get_generator(p):
    """
    p should be a prime, or you need to do factorization
    """
    g=[]
    for i in range(2,p-1):
        k=i
        sg=[]
        step=p
        while k!=1 and step>0:
            if k==0:
                raise ValueError(f"Damn, {i} generates 0 for group {p}")
            sg.append(k)
            k=(k*i)%p
            step-=1
        sg.append(1)
        # if len(sg)!=(p-1): continue
        g.append((i,[j for j in sg]))
    return g

Diffie-Hellman assumption

If pp is a randomly sampled safe prime.

Denote safe prime as ฮ ~n={pโˆˆฮ n:q=pโˆ’12โˆˆฮ nโˆ’1}\tilde{\Pi}_n=\{p\in \Pi_n:q=\frac{p-1}{2}\in \Pi_{n-1}\}

Then

P[pโ†ฮ n~;aโ†Zpโˆ—;g=a2โ‰ 1;xโ†Zq;y=gxmodโ€‰โ€‰p:A(y)=x]โ‰คฮต(n)P\left[p\gets \tilde{\Pi_n};a\gets\mathbb{Z}_p^*;g=a^2\neq 1;x\gets \mathbb{Z}_q;y=g^x\mod p:\mathcal{A}(y)=x\right]\leq \varepsilon(n)

pโ†ฮ n~;aโ†Zpโˆ—;g=a2โ‰ 1p\gets \tilde{\Pi_n};a\gets\mathbb{Z}_p^*;g=a^2\neq 1 is the function condition when we do the encryption on cyclic groups.

Notes: f:Zqโ†’Zpโˆ—f:\Z_q\to \mathbb{Z}_p^* is one-to-one, so f(A(y))โ€…โ€ŠโŸบโ€…โ€ŠA(y)=xf(\mathcal{A}(y))\iff \mathcal{A}(y)=x