HDUOJ-------(1211)RSA
RSA
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1135 Accepted Submission(s): 833
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) = 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.
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
何为快速幂.....自己百度去... 自己根据以往经验敲的...所以自己验证去吧...
说下简单的快速幂吧....
//求 ans=a的b次幂mod n
quick_pow(int a,int b,int ans,int n)
{
while(a)
{
if(a&1)
{
ans*=b;
ans%=n;
a--;
}
else
{
b*=b;
b%=n;
b>>=1;
}
}
}
扩展欧几里得代码:
1 // ax+by=c; c/q=k;(k=1,2,3,.....n)
2 int x,y,q;
3 void exgcd(int a ,int b)
4 {
5 if(b==0)
6 {
7 y=0,x=1,q=a;
8 }
9 else
10 {
11 int temp=x;
12 x=y;
13 y=temp-a/b*y;
14 }
15 }
简单题。。。。
代码:
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #define LL _int64
5 LL d,a,b;
6 /*ax+by=c*/
7 /*欧几里得扩展*/
8 void exgcd(LL x ,LL y)
9 {
10 if(y==0)
11 {
12 a=1,b=0,d=x;
13 }
14 else
15 {
16 exgcd(y,x%y);
17 LL temp=a;
18 a=b,b=temp-x/y*b;
19 }
20 }
21 int main()
22 {
23 LL p,q,e,len,key;
24 while(scanf("%I64d %I64d %I64d %I64d",&p,&q,&e,&len)!=EOF)
25 {
26 exgcd(e,(p-1)*(q-1));
27 while(a<0)
28 {
29 a+=(p-1)*(q-1);
30 }
31 LL n=p*q;
32 LL cnt=a;
33 while(len--)
34 {
35 scanf("%I64d",&key);
36 key%=n;
37 LL ans=1;
38 /*可以用快速幂*/
39 a=cnt;
40 while(a)
41 {
42 if(a&1)
43 {
44 ans*=key;
45 ans%=n;
46 a--;
47 }
48 else
49 {
50 key*=key;
51 key%=n;
52 a>>=1L;
53 }
54 }
55 putchar(ans);
56 }
57 putchar(10);
58 }
59 return 0;
60 }
- 监控平台前端SDK开发实践
- 一步步实现静态页面布局
- Stanford机器学习笔记-3.Bayesian statistics and Regularization
- 在R中使用支持向量机(SVM)进行数据挖掘
- 【你问我答】你与Java大牛的距离,只差这24个问题
- Android漏洞扫描工具Code Arbiter
- Huawei HG532 系列路由器远程命令执行漏洞分析
- postMessage与postMessage跨域
- 【手把手教你做项目】自然语言处理:单词抽取/统计
- D-Link系列路由器漏洞挖掘入门
- 大家一直在谈的领域驱动设计(DDD),我们在互联网业务系统是这么实践的
- 在Atom中设置Python开发环境
- Kaggle赛题解析:逻辑回归预测模型实现
- Shield:支撑美团点评品类最丰富业务的移动端模块化框架开源了
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android自带的四种线程池使用总结
- CentOS8.1搭建Gitlab服务器详细教程
- Android开发之图片旋转功能实现方法【基于Matrix】
- Android编程简单实现拨号器功能的方法
- win10 + Ubuntu20.04 LTS双系统引导界面美化
- Android开发从相册中选取照片的示例代码
- 详解Android WebView的input上传照片的兼容问题
- Ubuntu14.04安装、配置与卸载QT5的步骤详解
- CentOS 8 安装 MariaDB的详细教程
- Android中RecyclerView拖拽、侧删功能的实现代码
- Android单个RecyclerView实现列表嵌套的效果
- Android如何禁止向EditText控件中输入内容详解
- 小程序视角下同构方案思考
- Android基于自带的DownloadManager实现下载功能示例
- Linux服务器搭建nvidia-docker环境过程详解