# "D" is for Decryption

### Challenge:

Now that you know the correct RSA decryption value `d` from "D" is for Dumb Mistakes, can you use it to properly decrypt one of DEADFACE's private messages? The ciphertext that De Monne's security team intercepted was:

`992478-1726930-1622358-1635603-1385290`

Assuming each `-` character separates each letter of the ciphertext and every letter in the alphabet is represented by its position (i.e., a = 1, b = 2, etc.), what is the plaintext version of this message? Submit the flag as `flag{plaintext}`.

### Solution:

We generated all the required keys during the previous "D" is for Dumb Mistakes challenge so we can simply continue our Python session to perform the decryption:

``````\$ python3 -q
>>> p = 1049
>>> q = 2063
>>> e = 777887
>>> phi = (p - 1) * (q - 1)
>>> d = pow(e, -1, phi)
>>> print(d)
1457215
...
>>> from string import ascii_lowercase as AL
>>> print("".join([AL[pow(int(c),d,p*q)-1] for c in "992478-1726930-1622358-1635603-1385290".split("-")]))
ghost
``````

We leveraged Python's list comprehension to write a two-liner that:

1. Load a list of lowercase letters into AL
2. Spilt the provided ciphertext on the "-" character into the variable c
3. Convert c to an integer
4. Call `pow(c,d,p*q)` to decrypt and produce a number as described in the challenge
5. Perform a lookup of the alphabet letter based on AL list index (c - 1 to account for the 0-based list. a.k.a A=0, B=1, etc)
6. Join all the plaintext parts into a string

The accepted flag was: `flag{ghost}`

Published:

Updated: