# Mind your Ps and Qs

after getting the file we were given 3 variables

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FfG1fLmBLPG7xYZ7x2cQh%2Fimage.png?alt=media&#x26;token=6c507c31-dc41-427a-b770-4ac3560fe635" alt=""><figcaption></figcaption></figure>

so we got the ciphertext the n and e

so we can just find the p and q using tools

```python
p = 2434792384523484381583634042478415057961
q = 650809615742055581459820253356987396346063
```

then we can calculate the phi of n and d

φ(n) = (p - 1) \* (q - 1)

d = e^-1 mod φ(n)

now we can decrypt the flag cause we already have the d and n

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FbCoTiglIfb9m99bV3ESC%2Fimage.png?alt=media&#x26;token=dbf300a5-74f9-465d-b8f3-b960591b9470" alt=""><figcaption></figcaption></figure>

```python
from Crypto.Util import *

c = 964354128913912393938480857590969826308054462950561875638492039363373779803642185
n = 1584586296183412107468474423529992275940096154074798537916936609523894209759157543
e = 65537
p = 2434792384523484381583634042478415057961
q = 650809615742055581459820253356987396346063
en = (p-1)*(q-1)
d = number.inverse(e, en)

flag = pow(c, d, n)

decrypted_bytes = flag.to_bytes((flag.bit_length() + 7) // 8, byteorder='big')

print(decrypted_bytes.decode())
```
