hdu 1211 逆元
RSA
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2353 Accepted Submission(s): 1677
> 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) = me mod n
When you want to decrypt data, use this method :
M = D(c) = cd 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.
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.
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.
7716 7746 7497 126 8486 4708 7746 623 7298 7357 3239
using namespace std;
#define LL long long
#define lld long long
void exGcd (lld a, lld b, lld &d, lld &x, lld &y)
{
if (b == 0)
{
x = 1 ;
y = 0 ;
d = a ;
return ;
}
exGcd (b, a%b, d, x, y) ;
lld tmp = x ;
x = y ;
y = tmp - a/b*y ;
}
LL qpow(LL a,LL b,LL c)
{
LL r=1;
while(b){
if(b&1) r=r*a%c;
a=a*a%c;
b>>=1;
}
return r;
}
int main()
{
LL p,q,e,n,fn,l;
lld d,x,y;
while(cin>>p>>q>>e>>l){n=p*q;
fn=(p-1)*(q-1);
exGcd(e,fn,d,x,y);
x=(x%fn+fn)%fn;
for(int i=1;i<=l;++i){
LL num;
scanf("%lld",&num);
printf("%c",qpow(num,x,n));
}cout<<endl;
}
return 0;
}
hdu 1211 逆元的更多相关文章
- HDU 1211 EXGCD
EXGCD的模板水题 RSA算法给你两个大素数p,q定义n=pq,F(n)=(p-1)(q-1) 找一个数e 使得(e⊥F(n)) 实际题目会给你e,p,q计算d,$de \mod F(n) = 1$ ...
- hdu 1211 RSA (逆元)
RSA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 4828 逆元+catalan数
Grids Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- HDU 5651 逆元
xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- hdu 5685(逆元)
Problem A Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 1211
水.模拟即可.使用EXGCD求逆元 #include <iostream> #include <cstdio> #include <cstring> #includ ...
- hdu 1211 RSA
// 表示题目意思我是理解了蛮久 英语太水了 //首先这是解密公式 m=c^d mod n// 给你 p q e 然后 n=p*q fn=(p-1)*(q-1)// 给你 e,根据公式 e*d mod ...
- hdu 1576(逆元)
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 5976 数学,逆元
1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
随机推荐
- 解析库之——beautifulsoup
阅读目录 一 介绍 二 基本使用 三 遍历文档树 四 搜索文档树 五 修改文档树 六 总结 一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通 ...
- Leetcode 357
没用过Leetcode刷题,只能按照自己的想法随便写写了 思路:1.第一位数有9种(除了0)可能,第二位数有9种(除了第一位)可能,第三位数有8种(除了前两位)可能,以此类推...9*8*7*...( ...
- ansible一些基本操作
一.介绍 特性 (1).no agents:不需要在被管控主机上安装任何客户端: (2).no server:无服务器端,使用时直接运行命令即可: (3).modules in any languag ...
- $python用装饰器实现一个计时器
直接上代码: import time from functools import wraps # 定义装饰器 def fn_timer(function): @wraps(function) def ...
- 20145316许心远《Java程序设计》第5周学习总结
20145316 <Java程序设计>第5周学习总结 教材学习内容总结 异常处理 & Collection与Map 异常继承架构 错误的对象继承java.lang.Throwabl ...
- python 内建函数isinstance的用法以及与type的区别
isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数object是classinfo的实例,或者object是class ...
- 【虚拟机】linux 桥接模式 固定静态IP
1:在root用户下修改 2:进入root用户下 vim/etc/sysconfig/network-scripts/ifcfg-eth0 2.修改完保存退出 3.重启网络服务:service net ...
- 快用Visual Studio(三)- 代码重构
什么是代码重构 编写代码 | 找到代码 | 修改代码 关于重构的工具 Bracket Matching Selection Cursors Intelligence Parameter hints E ...
- spring 概念理解
一.Spring的IoC(Inversion of Control).这是Spring中得有特点的一部份.IoC又被翻译成“控制反转”,也不知道是谁翻译得这么别扭,感觉很深奥的词.其实,原理很简单,用 ...
- dubbo-admin与多注册中心(注册中心集群)
在使用dubbo时,注册中心是一个必要的架构组成成员.当我们的注册中心没有采取集群时,如何在dubbo-admin中配置,我们可以根据dubbo官方文档,很快找到我们的答案. 但是当注册中心集群之后怎 ...