博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1211 RSA (逆元)
阅读量:5880 次
发布时间:2019-06-19

本文共 2843 字,大约阅读时间需要 9 分钟。

RSA

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1243    Accepted Submission(s): 901

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) = m
e mod n
When you want to decrypt data, use this method :
M = D(c) = c
d mod 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
I-LOVE-ACM.
 

 

Author
JGShining(极光炫影)
 

 

Source
 

 

Recommend
Eddy   |   We have carefully selected several similar problems for you:            
 

 

1 //0MS    236K    1318 B    G++ 2 /* 3  4     题意: 5         RSA密码加解密法的解密 6      7     模拟题: 8         可以算水题,不过也磨了挺久,一是逆元求法不明确, 9     二是O(lgn)的n次方模数算法忘了,三是没注意64位,10     还有电脑有点卡!!郁闷 11 12 */13 #include
14 #include
15 /***************************************16 函数:ExGcd 17 功能:求两个数的最大公约数和模P的乘法逆元。18 输入:a,b 输入参数,求这两个数的最大公约数19 和a模b的逆元 或 b模a的逆元。20 输出:x,y 分别表示a模b的逆元和b模a的逆元。21 返回:r 表示a b 的最大公约数。22 *************************************/23 __int64 Exgcd(__int64 a,__int64 b,__int64 &x,__int64 &y)24 {25 if(b==0){26 x=1;27 y=0;28 return a;29 }30 __int64 r=Exgcd(b,a%b,x,y);31 __int64 t=x;32 x=y;33 y=t-a/b*y;34 return r;35 } 36 __int64 fac(__int64 a,__int64 d,__int64 n)37 {38 a%=n;39 int t=1;40 while(d){41 if(d%2) t=(t*a)%n; 42 a=(a*a)%n;43 d/=2;44 }45 return t;46 }47 int main(void)48 {49 __int64 p,q,e;50 __int64 l,a;51 while(scanf("%I64d%I64d%I64d%I64d",&p,&q,&e,&l)!=EOF)52 { 53 char c[105];54 memset(c,0,sizeof(c));55 __int64 d1=0,d2=0;56 __int64 n=p*q;57 Exgcd(e,(p-1)*(q-1),d1,d2);58 d1=(d1+(p-1)*(q-1))%((p-1)*(q-1));59 //printf("%d %d",d1,d2); 60 for(int i=0;i

 

转载于:https://www.cnblogs.com/GO-NO-1/p/3614660.html

你可能感兴趣的文章
android 电池(一):锂电池基本原理篇【转】
查看>>
Total Command 常用快捷键
查看>>
ionic 调用手机的打电话功能
查看>>
怎么使用阿里云直播服务应用到现在主流直播平台中
查看>>
Xcode全局替换内容,一键Replace
查看>>
1000 加密算法
查看>>
exif_imagetype() 函数在linux下的php中不存在
查看>>
Ruby的case语句
查看>>
Linux的链接文件-ln命令
查看>>
maven的tomcat插件如何进行debug调试
查看>>
table表头固定
查看>>
截取字符串中两个字符串中的字符串
查看>>
spring xml properties split with comma for list
查看>>
判断点是否在三角形内
查看>>
Android实战简易教程-第二十三枪(基于Baas的用户注冊验证username是否反复功能!)...
查看>>
在odl中怎样实现rpc
查看>>
leetcode 110 Balanced Binary Tree
查看>>
python活用isdigit方法显示系统进程
查看>>
项目开发总结
查看>>
知行合一
查看>>