Rating:

# next-level

## Description

With this challenge we are taking multiprime-RSA to the next level.

connection : `nc 52.59.124.14 5028`

## Source

- `chall.py`
```
from Crypto.Util import number

def nextprime(n):
p = n
while True:
if number.isPrime(p := p+1): return p

p = number.getPrime(512)
q = nextprime(p)
r = mextprime(q)
n = p*q*r
e = 0x10001
flag = int.from_bytes(open('flag.txt','r').read().encode())
c = pow(flag,e,n)
print(n)
print(c)
```

## Solution

- The three primes `p,q and r` are consecutive , so if we cube root `n`, all 3 primes should be close enough to it, after which we can do simple rsa decryption

```
import gmpy2
n = 1423696184138299187721136092634206795474228818359254562856094568636855171615678880920926722610547194602987761193449326507118359993594471435645826253316902235902897669704714553677203234166954499618999964422536091438971505784621329490069579642255524755202544032632183183957622109811013127191870429255987259007397636407468676098197927518740067976025609841911915123725670867493639305222851990187964736780063714533683145636015447029348885410704815499122341114042327169
c = 131651344873519256044666647667777517890425242822366915269194361395860207480771324688469277764519758696543460643053401849725715560248991554032155113023655305344500932982901292470503496367174305551466110466449423534576075224893017413815051092742781844533302820289782530644839133320449270939436862716388171106758883828888466839476571539086851311110250922243122195616209064056814722211733750357552399032629128807766413610713049086394292885523491311807724053718833773
# q = int(gmpy2.iroot(n,3)[0])
# for i in range(q-1000000,q+1000000):
# if n%i==0:
# print(i)
p,q,r = 11249652490699850711022522271657358429400746044550773056590144145734157894927763634286174175376040187876531881206052802474788398453265193915636441641399241,11249652490699850711022522271657358429400746044550773056590144145734157894927763634286174175376040187876531881206052802474788398453265193915636441641399671,11249652490699850711022522271657358429400746044550773056590144145734157894927763634286174175376040187876531881206052802474788398453265193915636441641400079
phi = (p-1)*(q-1)*(r-1)
d = pow(65537,-1,phi)
m = pow(c,d,n)
from Crypto.Util.number import *
print(long_to_bytes(m))
```

## Flag
`ENO{1_l0ve_7h3_pr1me_numb3r_the0r3m}`