Hack4S3cur1ty

[Seccon Beginners 2018][Crypto] RSA is Power 본문

CTFs/2018

[Seccon Beginners 2018][Crypto] RSA is Power

h4ck4s3cur1ty 2018. 5. 28. 23:41

N, E, C 값이 주어졌는데, factordb에서 N값을 인수분해 해보면 p와 q를 구할 수 있다.




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
from Crypto.Util.number import long_to_bytes
 
def xgcd(b, n):
    x0, x1, y0, y1 = 1001
    while n != 0:
        q, b, n = b // n, n, b % n
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return  b, x0, y0
 
def mulinv(b, n):
    g, x, _ = xgcd(b, n)
    if g == 1:
        return x % n
 
= 299681192390656691733849646142066664329
= 324144336644773773047359441106332937713
= 65537
= p * q
pin = (p-1)*(q-1)
= mulinv(e, pin)
 
enc = 77361455127455996572404451221401510145575776233122006907198858022042920987316
 
print long_to_bytes(pow(enc,d,n))
cs


Comments