write-ups-challenges-2021-2022/prime_magic/SOLUTION.md

28 lines
1.3 KiB
Markdown
Raw Normal View History

2021-12-02 23:33:26 +00:00
## Difficulty
Medium. 60 points
## How to Solve
Explanation on RSA encryption can be found here: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
You get the values c, n and e:
* c is the encrypted message
* n is the modulus
* e is the public key of the receiver
You are supposed to find m, the decrypted message. Doing so requires to find some auxiliary values
### p and q
p and q are two prime numbers that you can find by factoring n. A handy tool exists online: http://factordb.com/index.php
### phi(n)
phi(n) = (p - 1) * (q - 1)
### private key d
d is the private key of the receiver. Since we are intercepting this message, we do not have access to the d, but we can calulate it by doing (d * e) = 1 (modulo phi(n)). Note that this will take a long time. A faster way is to use multiplicative inverse, which you can find in several math libraries of the language of your choice.
### Decrypting c to m
This can be done using c ^ d (mod n). Use a library function to calculate this, since they use faster algorithms. This will grant you a decimal number, not the flag yet. Convert this to hex, and split the hex string in pairs of two to get the hex numbers for ascii characters. Translate to ascii and you will be granted with the flag.
## Flag
IGCTF{WINGarduimLEViosa}