RSA
Time limit2sMemory limit512 MB
Factor N into its two primes to recover phi(N), then use modular inverse and fast exponentiation to decrypt C and print M.
- Level
Medium5 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
RSA is one of the most widely used public key encryption algorithms. Its basic operation is described below.
Pick two distinct odd primes and and compute . Next compute the totient and pick an integer with and . Finally compute , the multiplicative inverse of modulo , that is the integer with .
This gives the public key, formed by the two integers and , and the secret key, formed by the two integers and .
To encrypt a message with , compute , and is the encrypted message. To decrypt it and recover the original message, compute . Decryption needs the secret key, and the public key alone is not enough. The expression used above means that the remainder of divided by is 1.
In this problem you break RSA. Write a program that recovers the original message from the public key , and the ciphertext alone.
Input
The single line of input contains three integers , , separated by spaces, where , and .
and form the RSA public key described above, and is a message encrypted with that public key. is a product of two distinct odd primes, and always holds.
Output
Print a single line containing the original message , where .