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.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
随机推荐
- 项目总结之HashMap问题
在项目中我需要用另一个项目的中的方法,在另一个项目中的方法返回值是一个hashmap,返回的不是一个hashMap中存的对象而是Object对象.在一个项目中调用另一个项目中的方式是直接引入另一个项目 ...
- 转:centos彻底删除文件夹、文件命令
转自:http://www.cnblogs.com/kluan/p/4458296.html centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkd ...
- filebeat+logstash通过zabbix微信报警
一.安装软件: 1.在要收集日志的机器上安装filebeat: 1).下载安装: cd /usr/local/src wget https://artifacts.elastic.co/downloa ...
- 131. Palindrome Partitioning(回文子串划分 深度优先)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...
- Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice Time Limit:1000MS Memory Limit:65536KB Description There are 2 special dices on the table. ...
- iOS开发之HelloKit代码片段
完整代码托管:https://github.com/1042710553/HelloKit.git /************************/plist/****************** ...
- python3_ftp文件传输
Python中的ftplib模块 Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件 FTP的工作流程及基本操作可参考协议RFC95 ...
- 在使用Kafka过程中遇到的错误
问题一:用kafka命令发送消息时候,一直报WARN Error while fetching metadata with correlation id 0 : {test=UNKNOWN_TOPIC ...
- JS动态事件绑定问题
今天搞一个连环套的动态选项展示,需要给下拉框动态绑定事件,谁知绑定中出现问题,总是执行第一次绑定的时间而后续绑定的事件没有被触发. //重写增加行方法 function initMainItem(gr ...