Breaking the Cipher

시간 제한1초메모리 제한2048 MB

요약
RSA 매개변수 p, q, e와 암호문 C가 주어질 때 복호화 지수 d를 구하고 M = C^d mod n을 계산한다.
난이도

보통10점 중 4점

유형
수학, 정수론
정답자
아직 제출이 없습니다

문제

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:

  1. Choose two distinct prime numbers pp and qq.
  2. Compute n=pqn = pq.
  3. Compute ϕ(n)=ϕ(p)⋅ϕ(q)=(p−1)⋅(q−1)=n−(p+q−1)\phi(n) = \phi(p)\cdot \phi(q) = (p - 1)\cdot (q - 1) = n - (p + q - 1), where ϕ\phi is Euler's totient function.
  4. Choose an integer ee such that 1<e<ϕ(n)1 < e < \phi(n) and gcd(e,ϕ(n))=1(e, \phi(n)) = 1; i.e., ee and ϕ(n)\phi(n) are coprime.
  5. Determine dd as d≡e−1(modϕ(n))d \equiv e^{-1} \pmod{\phi(n)}; i.e., d⋅e≡1(modϕ(n))d \cdot e \equiv 1 \pmod{\phi(n)}.

Encryption:

Suppose that Bob would like to send message MM to Alice. He then computes the ciphertext CC, using Alice's public key ee, corresponding to \begin{equation*} C \equiv M^e \pmod{n} \end{equation*}

Decryption:

Alice can recover MM from CC by using her private key exponent dd 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 pp, qq, and ee accordingly and needs your help to decrypt the message CC she has received from Bob.

입력

The input to this problem is structured as follows: The first line contains three integers, 1<p,q,e<10001 < p, q, e < 1000, respectively. The second line contains one integer CC, the encrypted secret combination to Alice's safe.

출력

One line with the (decrypted) combination MM to Alice's safe.

예제3

  1. 예제 1

    입력
    751 337 739
    735
    
    예상 출력
    15075
    
  2. 예제 2

    입력
    181 677 739
    567
    
    예상 출력
    11662
    
  3. 예제 3

    입력
    467 823 397
    802
    
    예상 출력
    368133