饭宝 发表于 2024-10-22 13:06:01

HDU RSA

https://i-blog.csdnimg.cn/direct/9498f2ff9a304144855a7f0ee5cf5d24.png
翻译成中文后:
https://i-blog.csdnimg.cn/direct/41c66eb77ec743038d4657267c69d02a.png
思路:由题易得,d * e +y * f ( n ) = 1 ,且gcd ( e , f ( n ) ) = 1,以是用扩展欧几里得求出 d ,但要包管 d 好坏负的,最有用快速幂求出每个字符即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
int exgcd(int a,int b,int &x,int &y){
        if(b==0){
                x=1,y=0;
                return a;
        }
        int gcd=exgcd(b,a%b,y,x);
        y-=a/b*x;
        return gcd;
}
int ksm(int x,int y,int p){
        int ans=1;
        while(y){
                if(y&1) ans=ans*x%p;
                x=x*x%p;
                y>>=1;
        }
        return ans;
}
signed main(){
        int p,q,e,l;
        while(cin >> p >> q >> e >> l){
                int n=p*q,f=(p-1)*(q-1);
                while(l--){
                        int c,x,y;
                        cin >> c;
                        int gcd=exgcd(e,f,x,y);
                        x=(x+f)%f;
                        cout << (char)ksm(c,x,n);
                }
                cout << endl;
        }
        return 0;
}


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: HDU RSA