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) = 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   |   We have carefully selected several similar problems for you:  1299 1695 1573 1213 1576 
 
 //0MS    236K    1318 B    G++
/* 题意:
RSA密码加解密法的解密 模拟题:
可以算水题,不过也磨了挺久,一是逆元求法不明确,
二是O(lgn)的n次方模数算法忘了,三是没注意64位,
还有电脑有点卡!!郁闷 */
#include<stdio.h>
#include<string.h>
/***************************************
函数:ExGcd
功能:求两个数的最大公约数和模P的乘法逆元。
输入:a,b 输入参数,求这两个数的最大公约数
和a模b的逆元 或 b模a的逆元。
输出:x,y 分别表示a模b的逆元和b模a的逆元。
返回:r 表示a b 的最大公约数。
*************************************/
__int64 Exgcd(__int64 a,__int64 b,__int64 &x,__int64 &y)
{
if(b==){
x=;
y=;
return a;
}
__int64 r=Exgcd(b,a%b,x,y);
__int64 t=x;
x=y;
y=t-a/b*y;
return r;
}
__int64 fac(__int64 a,__int64 d,__int64 n)
{
a%=n;
int t=;
while(d){
if(d%) t=(t*a)%n;
a=(a*a)%n;
d/=;
}
return t;
}
int main(void)
{
__int64 p,q,e;
__int64 l,a;
while(scanf("%I64d%I64d%I64d%I64d",&p,&q,&e,&l)!=EOF)
{
char c[];
memset(c,,sizeof(c));
__int64 d1=,d2=;
__int64 n=p*q;
Exgcd(e,(p-)*(q-),d1,d2);
d1=(d1+(p-)*(q-))%((p-)*(q-));
//printf("%d %d",d1,d2);
for(int i=;i<l;i++){
scanf("%I64d",&a);
a=fac(a,d1,n);
int b=a;
c[i]=b;
//printf("%d %d %c\n",a,c[i],c[i]);
}
puts(c);
}
return ;
}

hdu 1211 RSA (逆元)的更多相关文章

  1. hdu 1211 RSA

    // 表示题目意思我是理解了蛮久 英语太水了 //首先这是解密公式 m=c^d mod n// 给你 p q e 然后 n=p*q fn=(p-1)*(q-1)// 给你 e,根据公式 e*d mod ...

  2. 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$ ...

  3. hdu 1211 逆元

    RSA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. HDU 1576 (乘法逆元)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1576 题目大意:求(A/B)mod 9973.但是给出的A是mod形式n,n=A%9973. 解题思 ...

  5. HDU 5651 组合+逆元

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5651 题目意思我看了半天没读懂,一直以为是回文子串又没看见substring的单词最后看博客才知道是用给 ...

  6. hdu 1576 求逆元

    题意:给出n=A mod 9973和B,求(A/B) mod 9973 昨天用扩展欧几里得做过这题,其实用逆元也可以做. 逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元. 求逆元方 ...

  7. HDU 1211

    水.模拟即可.使用EXGCD求逆元 #include <iostream> #include <cstdio> #include <cstring> #includ ...

  8. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  9. HDU 5651 计算回文串个数问题(有重复的全排列、乘法逆元、费马小定理)

    原题: http://acm.hdu.edu.cn/showproblem.php?pid=5651 很容易看出来的是,如果一个字符串中,多于一个字母出现奇数次,则该字符串无法形成回文串,因为不能删减 ...

随机推荐

  1. 面试-Spring理解

    转自http://hui.sohu.com/infonews/article/6331404387079946240 spring呢,是pivotal公司维护的一系列开源工具的总称,最为人所知的是sp ...

  2. 变量类型 ROWID 和 UROWID

    ROWID:    ROWID为该表行的唯一标识,是一个伪列,这个伪列可以用SELECT查看,但是不可以用INSERT, UPDATE来修改,不可以用DELETE来删除. UROWID: ROWID可 ...

  3. dts--tests(一)

    cmdline.py """ DPDK Test suite. Test cmdline. """ import utils from te ...

  4. php扩展开发-全局变量

    //php_myext.hZEND_BEGIN_MODULE_GLOBALS(myext) unsigned long counter;//在这里定义需要的全局变量,可以多个,每个变量一行, ZEND ...

  5. 如何在创建hive表格的python代码中导入外部文件

    业务场景大概是这样的,我要对用户博文进行分词(这个步骤可以看这篇文章如何在hive调用python的时候使用第三方不存在的库-how to use external python library in ...

  6. Python学习笔记:logging(日志处理)

    在一个软件中,日志是可以说必不可少的一个组成部分,通常会在定位客户问题或者记录软件使用情况等场景中会用到.logging模板块是Python的一个内置标准库,用于实现对日志的控制输出,对于平常的日志输 ...

  7. C# 控件置于最顶层、最底层、隐藏、显示

    控件置于最顶层.最底层 pictureBox1.BringToFront();//将控件放置所有控件最前端 pictureBox1.SendToBack();//将控件放置所有控件最底端 控件隐藏.显 ...

  8. 通过aop添加日志管理

    1.使用spring 的 aop 技术切到自定义注解上,所以先创建一个自定义注解类 import java.lang.annotation.*; @Target(ElementType.METHOD) ...

  9. 在MAC下使用Robotframework+Selenium2【第二枪】如何处理Table点击指定记录

    1.通过关键字Get Matching Xpath Count获取table中的记录 2.遍历Table所有记录 3.判断记录是否符合条件,做点击操作

  10. BZOJ 3027: [Ceoi2004]Sweet

    容斥 #include<cstdio> using namespace std; int a,b,n,m[15]; long long ans=0,mod=2004; long long ...