Breaking the Cipher
시간 제한1초메모리 제한2048 MB
RSA 매개변수 p, q, e와 암호문 C가 주어질 때 복호화 지수 d를 구하고 M = C^d mod n을 계산한다.
문제
It has already been years since Alice moved into her new house in the countryside, but only a week ago she suddenly found a mysterious safe, requiring a secret combination to unlock, hidden in her basement. She jumped onto the internet to ask strangers for clues and she received a message from a mysterious man called Bob. He included the combination to Alice's safe, but noted that he had encrypted it with the RSA algorithm using Alice's public key. On the internet you find that the RSA algorithms works as follows:
Key generation:
- Choose two distinct prime numbers and .
- Compute .
- Compute , where is Euler's totient function.
- Choose an integer such that and gcd; i.e., and are coprime.
- Determine as ; i.e., .
Encryption:
Suppose that Bob would like to send message to Alice. He then computes the ciphertext , using Alice's public key , corresponding to \begin{equation*} C \equiv M^e \pmod{n} \end{equation*}
Decryption:
Alice can recover from by using her private key exponent by computing \begin{equation*} M \equiv C^d \pmod{n} \end{equation*} Additionally, Alice has learned that the following congruence could prove to be useful for the decryption process: \begin{equation*} (a \cdot b) \mod{n} \equiv ((a \mod{n}) \cdot (b \mod{n})) \mod{n} \end{equation*}
Alice has already chosen the integers , , and accordingly and needs your help to decrypt the message she has received from Bob.
입력
The input to this problem is structured as follows: The first line contains three integers, , respectively. The second line contains one integer , the encrypted secret combination to Alice's safe.
출력
One line with the (decrypted) combination to Alice's safe.