#P5451. [THUPC 2018] 密码学第三次小作业
[THUPC 2018] 密码学第三次小作业
Background
In 1977, Ronald Rivest, Adi Shamir, and Leonard Adleman proposed the RSA encryption algorithm. RSA is an asymmetric encryption algorithm, and its security depends on the difficulty of factoring very large integers. In other words, the harder it is to factor a very large integer, the more reliable RSA is. If someone finds a fast factoring algorithm, then the security of information encrypted with RSA will definitely drop a lot.
The basic idea of RSA is as follows:
- Generating the public key and private key
- Randomly choose two different large primes and , and compute .
- By the property of Euler's totient function, compute .
- Choose a positive integer less than such that and are coprime. Then compute the multiplicative inverse of modulo , satisfying .
- Destroy the records of and . At this point, is the public key, and is the private key.
- Message encryption: First, convert the message into an integer that is less than and coprime with , in a format agreed upon by both parties. If the message is too long, it can be split into several parts (this is what we call block encryption). Then each part is encrypted using:
- Message decryption: Decrypt using the key :
Problem Description
Now there are two users who, by coincidence, have the same modulus but different private keys. Let their public keys be and , and they are coprime. The plaintext message is , and the ciphertexts are:
$$\begin{matrix}c_1=m^{e_1}\bmod N\\c_2=m^{e_2}\bmod N\end{matrix}$$Now, an attacker has intercepted , , , , and . Please help him recover the plaintext .
Input Format
The input contains multiple test cases. The first line contains an integer indicating the number of test cases, and it is guaranteed that . Then each test case is described as follows:
- One line contains five positive integers , , , , . It is guaranteed that , has exactly two prime factors, and the other values are generated strictly according to the RSA algorithm described above.
Output Format
For each test case, output line:
- A non-negative integer . Please make sure that when outputting. It is guaranteed that the answer is coprime with .
1
1502992813 2511821915 653507 57809 2638352023
19260817
Hint
Copyright Information
From the 2018 Tsinghua University Programming Contest and Intercollegiate Invitational (THUPC2018). Thanks to Pony.ai for supporting this contest.
Solutions and other resources can be found at https://github.com/wangyurzee7/THUPC2018.
Translated by ChatGPT 5