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.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
随机推荐
- PHP 语言结构(Language constructs)和函数的区别
相信大家经常看到对比一些PHP应用中,说用isset() 替换 strlen(),isset比strlen执行速度快等. 例子: if ( isset($username[5]) ) { // The ...
- Mac Angular打包报错xcode-select: error: tool 'xcodebuild' requires Xcode
Mac Angular打包报错: Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer ...
- (转)C语言中Exit函数的使用
C语言中Exit函数的使用 exit() 结束当前进程/当前程序/,在整个程序中,只要调用 exit ,就结束return() 是当前函数返回,当然如果是在主函数main, 自然也就结束当前进程了,如 ...
- nginx 413文件上报太大
在nginx使用过程中,上传文件的过程中,通常需要设置nginx报文大小限制.避免出现413 Request Entity Too Large. 于是奇葩的问题被我们遇到了,详细配置请参考下面.我们的 ...
- Hexo博客部署codingNet静态资源无法加载
用Hexo搭建的个人博客,部署到github的pages的话,好像百度搜索不到.所以在国内的codingNet的pages服务也一起部署一下,这样方便国内国外搜索引擎收录进来.具体部署教程我是参考这里 ...
- HttpWebRequest 返回BadRequest(400) 同时返回Response
今天用Fiddler分析安卓APP的一个登陆功能的时候,账号和密码错误会返回相应的消息,并且状态码是400. 正常用法: /// <summary> /// 读取返回的内容 /// < ...
- ubuntu下通过mono+jexus布署mvc5网站
本文使用的ubuntu为14.04 LTS 一.安装mono,本文使用源码安装的方式 1.搭架mono编译环境 sudo apt-get update sudo apt-get install bui ...
- Django学习笔记之Django的url反向解析
0x00 URL反向解析和三种不同的反向解析方式 Django中提供了关于URL的映射的解决方案,可以做两个方向的使用: 1.普通解析过程:由客户端的浏览器发起一个url请求,Django根据URL解 ...
- MVC 4中的前端渲染 @Helper指令
如果我们需要在一个页面或多个页面显示如人民币格式(后台传回来的无¥)¥的格式化.或是对后台数据作如保留小数个数等处理,这些东西经常要用到,特别是一些NULL值的处理,有可能会出错.这时我们可以通过创建 ...
- 20145329《Java程序设计》第八周学习总结
教材学习内容总结 日志 1.java.util.logging包提供了日志功能相关类与接口. 2.使用日志的起点是Logger类,Longer类的构造函数标示为protected,不同包的类药取得Lo ...