HDU1211 RSA(数论)

题目链接

分析:

组队赛时做的这题,不得不说,感慨万千。

因为题目给的是加密文,要求解密,所以就用M = D(c) = cd mod n。 如何d呢,推了推,觉得d是e的乘法逆。结果没过。

后来一商量,觉得ASCII也就那么几个,预处理出来不就完了么?这样,是可以A的,不过在比赛的时候,因为一时疏忽,将一个字母打错(注意是一个字母),一直找BUG。结果没来得及。比赛结束才发现打错了个字母。可恨的是,不论怎么改,样例都过,样例给的真是够“奇妙”的。

 

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>

using namespace std;

typedef unsigned long long LL;

LL pow_mod(LL a, LL b, LL n) {
    if(b == 0) return 1;
    LL ans = pow_mod(a, b/2, n);
    ans = (ans*ans)%n;
    if(b % 2 == 1) ans = (ans * a) % n;
    return ans;
}

int main()
{
    LL p, q, e;
    int l;
    map<LL, char> a;
    while(cin >> p >> q >> e >> l) {
        LL n = p*q;
        a.clear();
        for(int i=0; i<=255; i++) {
            a[pow_mod(i, e, n)] = (char)i;
        }

        LL c;
        for(int i=0; i<l; i++) {
            cin >> c;
            if(a[c] != ' ')
            cout << a[c];
        }
        putchar('\n');
    }

    return 0;
}

 

转载于:https://www.cnblogs.com/tanhehe/archive/2013/06/06/3122930.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值