Hack4S3cur1ty
[Seccon Beginners 2018][Crypto] RSA is Power 본문
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 = 1, 0, 0, 1 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 p = 299681192390656691733849646142066664329 q = 324144336644773773047359441106332937713 e = 65537 n = p * q pin = (p-1)*(q-1) d = mulinv(e, pin) enc = 77361455127455996572404451221401510145575776233122006907198858022042920987316 print long_to_bytes(pow(enc,d,n)) | cs |
'CTFs > 2018' 카테고리의 다른 글
[Seccon Beginners 2018][Pwn] condition (0) | 2018.05.28 |
---|---|
[Seccon Beginners 2018][MISC] てけいさんえくすとりーむず (0) | 2018.05.28 |
[Seccon Beginners 2018][Rev] Simple Auth (0) | 2018.05.28 |
[Seccon Beginners 2018][Rev] crackme (0) | 2018.05.28 |
[Seccon Beginners 2018][Rev] Activation (0) | 2018.05.28 |
Comments