RSA
Problem Description
RSA 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.
Input
Each 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.
Output
For 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 should output them as visualable letters with no blank between them.
Sample Input
101 103 7 11
7716 7746 7497 126 8486 4708 7746 623 7298 7357 3239
Sample Output
Author
JGShining(极光炫影)
Source
Recommend
Eddy
这才开始做题没多久,心思果然还不够细腻!这道题不认真不还摸不着头脑!细细品尝才得出味道!代码如下:
#include<iostream>
using namespace std;
int main()
{
int i,sum,k,fn,temp;
int p,q,e,d,l,n;
while(scanf("%d%d%d%d",&p,&q,&e,&l)!=EOF)
{
n=p*q;
fn=(p-1)*(q-1); d=1;
//第一步,先要求出d值,直接用暴力法求!
while(d*e%fn !=1) d++;
for(k=1;k<=l;k++)
{
cin>>temp;
for(i=1,sum=1;i<=d;i++)
{
sum=sum*temp;
sum=sum%n;
}//求出sum,这里是一边求乘积,一边取余,结果和求完乘积后再取余是一致的!
printf("%c",sum);
}
cout<<endl;
}
system("pause");
return 0;
}
/*
#include <stdio.h>
int main()
{
int p,q,e,l;
int c;//密文
while(scanf("%d%d%d%d",&p,&q,&e,&l)!=EOF){
int n=p*q;//计算出 p、q 的积 n = p × q
int fn=(p-1)*(q-1);
int d=1;
while((d*e)%fn!=1){//计算出 d, 使 d × e mod F(n) = 1 mod F(n), d 将用来作私钥
d++;
} //e=7,d=8743
while(l--)
{
scanf("%d",&c);
//int m=(c*d)%n;
//char m1=(char)m;
// printf("%c",m1);
int t=1;
for(int j=1;j<=d;j++){//M = D(c) = c^d mod n 解密公式
t*=c;
t%=n;
}
char tc=t;
printf("%c",tc);
}
printf("\n");
}
return 0;
}
*/
分享到:
相关推荐
杭电oj1000题解题报告
杭电OJ题目分类的叙述,可以方便去学习去做。
杭电OJ 2028代码 the rosolve of the hdu 2028
杭电OJ(1000-1099) AC 代码
本资源主要提供了杭电oj题目分类和自测状况两大类 可实现随机选题等功能.
杭电OJ部分威士忌的代码 杭电OJ部分威士忌的代码杭电OJ部分威士忌的代码
杭电oj上的一些疑问,适用于初学者,可以解答一些疑问 都是一些水题
杭电oj 1047习题
杭电oj分类
杭州电子科技大学 oj离线版
这是HDUOJ上面的140道题目的答案,其中大部分都是简单题,有些太简单的就没有收集进去,代码为C/C++,全都AC了的,其中有些有具体的说明是怎么做的,例如博弈论那些
课程资源 杭电OJ1000-1099答案 ,仅供参考...
杭电oj的离线版以及题目分类的文档 更加一目了然 方便选择适合的题目做 适合暂时上不了网的用于练习
这是杭电OJ上某些题的解题报告,后续还有上传很多!
基于Laravel 5.0的OJ题解网站 , 目前涵盖安科OJ,南阳OJ,杭电OJ ,北大OJ,浙大OJ.zip
杭电oj1048答案,c++代码,适合初学者,思路简单
这是杭电oj入门100题的题号,通过这100题可以掌握基本输入输出操作,及基本算法
杭电ACM2000-2011题已提交的代码!保证正确!