HDU 1211 RSA (series questions)

Source: Internet
Author: User
RSA

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 706 accepted submission (s): 524

Problem descriptionrsa is one of the most powerful methods to encrypt data. The RSA algorithm is described as follow:

> Choose two large prime integer p, q
> Calculate n = p × Q, calculate F (n) = (p-1) × (Q-1)
> Choose an integer e (1 <e <F (n), making gcd (E, F (N) = 1, E will be the Public Key
> Calculate d, making D × E Mod f (n) = 1 Mod f (n), and D will be the private key

You can encrypt data with this method:

C = E (m) = mEMOD n

When you want to decrypt data, use this method:

M = D (c) = CDMOD n

Here, C is an integer ASCII value of a Letter of cryptograph and M is an integer ASCII value of a Letter of plain text.

Now given p, q, E and some cryptograph, your task is to "translate" the cryptograph into plain text.

 

Inputeach case will begin with four integers p, q, E, l followed by a line of cryptograph. the integers p, q, E, l will be in the range of 32-bit integer. the cryptograph consists of L integers separated by blanks.

 

Outputfor each case, output the plain text in a single line. you may assume that the correct result of plain text are visual ASCII letters, you shocould output them as visualable letters with no blank between them.

 

Sample input101 103 7 11 7716 7746 7497 126 8486 4708 7746 623 7298 7357 3239

 

Sample outputi-LOVE-ACM.

 

Authorjgshining (Aurora shadow)

 

Source hangdian ACM provincial training team trials

 

It's shameful to recommendeddy. I can even enumerate it.
# Include <stdio. h>
Int Main ()
{
Int P, Q, E, L;
Int C;
Int N;
Int FN;
Int Temp;
Int D;
While (Scanf ( " % D " , & P, & Q, & E, & L )! = EOF)
{
N = p * q;
Fn = (p- 1 ) * (Q- 1 );
D = 1 ;
While (D * E % FN! = 1 ) D ++;
For ( Int I = 0 ; I <L; I ++)
{
Scanf ( " % D " , & C );
Temp = 1 ;
For ( Int J = 0 ; J <D; j ++)
{
Temp = (temp * C) % N;
}
Printf ( " % C " , Temp );
}
Printf ( " \ N " );
}
Return 0 ;
}
It's too violent. In fact, we should use the Extended Euclidean method to solve the equation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.