#P5451. [THUPC 2018] 密码学第三次小作业

[THUPC 2018] 密码学第三次小作业

Description

Now there are two users who, by coincidence, have the same modulus NN but different private keys. Let their public keys be e1e_1 and e2e_2, and they are coprime. The plaintext message is mm, 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 c1c_1, c2c_2, e1e_1, e2e_2, and NN. Please help him recover the plaintext mm.

Input Format

The input contains multiple test cases. The first line contains an integer TT indicating the number of test cases, and it is guaranteed that 1T1041\le T\le 10^4 . Then each test case is described as follows:

  • One line contains five positive integers c1c_1, c2c_2, e1e_1, e2e_2, NN. It is guaranteed that 28<N<2632^{8}< N < 2^{63}, NN 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 11 line:

  • A non-negative integer mm. Please make sure that 0m<N0\le m<N when outputting. It is guaranteed that the answer mm is coprime with NN.
1
1502992813 2511821915 653507 57809 2638352023
19260817

Hint

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