CTF/system32.kr

[system32.kr] RSA101

pental 2020. 9. 28. 16:12

p = 11820547749265118607908336189140061659994883367758644383099900753008997316272341754974105712436833864387373302687964986221522289414610698068230842231006759
q = 2076478388690715447644222392295584753007140199740835763821170999934221864895193172716587341806099928941239417181782165665806324184552950128351328886814107
e = 65537
c = 15175007508230661949213125841853820919948368859221761481847700530363990883761097704372435675552656459480039957857925187102590466676354015036181849182155680399350099015532296504916485091012255771133872737687990897080899160898509685794777509104691093814282101492973637294053730555124794841034604131492169339102

p, q, e, c가 주어진다. => 결국 d값을 구하는것

defenit.kr/2019/09/24/Crypto/%E3%84%B4%20Research/RSA_for_CTF/

 

RSA for CTF

목차 RSA Key Gen RSA 암호화 및 복호화 암호화 복호화 RSA 문제 종류 d값 계산 낮은 지수 공격 n값 소인수 분해 및 DB 이용 위너 공격 하스타드 공격 선택 암호문 공격 p, q값이 비슷할 경우 n 값으로 p, q

defenit.kr

RSA에 대해서 잘 정리 되어 있다.

import crypto
from gmpy2 import *

p = 11820547749265118607908336189140061659994883367758644383099900753008997316272341754974105712436833864387373302687964986221522289414610698068230842231006759
q = 2076478388690715447644222392295584753007140199740835763821170999934221864895193172716587341806099928941239417181782165665806324184552950128351328886814107
e = 65537
c = 15175007508230661949213125841853820919948368859221761481847700530363990883761097704372435675552656459480039957857925187102590466676354015036181849182155680399350099015532296504916485091012255771133872737687990897080899160898509685794777509104691093814282101492973637294053730555124794841034604131492169339102

n = p * q
phi = (p - 1) * (q - 1)

d = divm(1, e, phi)
result = ('%x' % pow(c, d, n))
print(result)
print(bytes.fromhex(result).decode('utf-8'))