Contents

# 基本类型：

## 1. “老奶奶用脚都会做"的板子题

$d$ = $e^{-1}$ mod $\phi(n)$

## 2. 已知e,d,n求p,q

$$\begin{cases} N = p * q \\[2ex] \phi(n)=(q-1)(p-1) \end{cases}$$

$$\begin{cases} N-\phi(n)+1=p+q \\[2ex] N=p * q \end{cases}$$

## 3.低加解密指数攻击

1. 已知c和已知e过小就请直接爆破
2. 低加密指数广播攻击->套用中国剩余定理模板
3. 低解密指数攻击->脚本梭哈,试了一下不好用

## 已知 n,e,d 求 q , p

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43   import random def gcd(a, b): if a < b: a, b = b, a while b != 0: temp = a % b a = b b = temp return a def getpq(n, e, d): p = 1 q = 1 while p == 1 and q == 1: k = d * e - 1 g = random.randint(0, n) while p == 1 and q == 1 and k % 2 == 0: k /= 2 y = pow(g, k, n) if y != 1 and gcd(y-1, n) > 1: p = gcd(y-1, n) q = n/p return (p, q) def main(): ''' n= e= d= ''' p, q = getpq(n, e, d) print( "p="+hex(p)) print( "q="+hex(q)) if __name__ == '__main__': main()