RSA破解

作者: nnnnzyx | 来源:发表于2017-11-14 17:59 被阅读0次

问题:

Alice decides to use RSA with the public key N = 1889570071. In order to guard against transmission errors, Alice has Bob encrypt his message twice, once using the encryption exponent e1 = 1021763679 and once using the encryption exponent e2 = 519424709. Eve intercepts the two encrypted messages c1 = 1244183534 and c2 = 732959706. Assuming that Eve also knows N and the two encryption exponents e1 and e2. Please help Eve recover Bob’s plaintext without finding a factorization of N.

分析:

RSA加密可得以下两条式子(M是明文)
C1=Me1 mod N
C2=Me2 mod N
由题目易知e和e2互素,即
gcd(e1,e2)=1
由扩展欧几里得算法便可得出
e1s+e2t=1
假设t<0, s>0, 则有
C1s * (C2-1)-t mod N
=C1s * C2t mod N
=Me1s * Me2t mod N
=Me1s+e2t mod N
=M mod N
=M

结论:

1、由扩展欧几里得算法求出s, t.
2、在 mod N的条件下求出C2-1.
3、计算 C1s * (C2-1)-t mod N, 结果即为明文M.

实现代码:

#include <iostream>
#include<gmp.h>
#include<gmpxx.h>
using namespace std;

//a*b mod c
mpz_class Mul(mpz_class a,mpz_class b,mpz_class c)
{
    mpz_class temp=0;
    while(b!=0)
    {
        if(b%2==1)
        {
            --b;
            temp=(temp+a)%c;
        }
        b/=2;
        a=(a+a)%c;
    }
    return temp;
}

// a^b mod c
mpz_class Pow(mpz_class a,mpz_class b,mpz_class c)
{
    mpz_class temp=1;
    while(b!=0)
    {
        if(b%2==1)
        {
            temp=Mul(temp,a,c);
        }
        b /=2;
        a=Mul(a,a,c);
    }
    return temp;
}

//a*s+b*t=gcd(a,b)=1 (a>b)
void exGcd(mpz_class a, mpz_class b,mpz_class &s,mpz_class &t)
{
    mpz_class temp;
    mpz_class q,r,x1=1,x2=0,y1=0,y2=1;
    mpz_class tmp_a=a;
    mpz_class tmp_b=b;
    while((r=tmp_a%tmp_b)!=0)
    {
        q=tmp_a/tmp_b;
        temp=x2;
        x2=x1-q*x2;
        x1=temp;
        temp=y2;
        y2=y1-q*y2;
        y1=temp;
        tmp_a=tmp_b;
        tmp_b=r;
    }
    s=x2;
    t=y2;
}

int main()
{
    mpz_class e1=1021763679;
    mpz_class e2=519424709;
    mpz_class c1=1244183534;
    mpz_class c2=732959706;
    mpz_class n=1889570071;

    mpz_class s,t;
    exGcd(e1,e2,s,t);
    if(s<0)
    {
        s=-s;
        mpz_invert(c1.get_mpz_t(),c1.get_mpz_t(),n.get_mpz_t());
    }
    if(t<0)
    {
        t=-t;
        mpz_invert(c2.get_mpz_t(),c2.get_mpz_t(),n.get_mpz_t());
    }
    cout<<"the result is "<<Mul(Pow(c1,s,n),Pow(c2,t,n),n)<<endl;

    return 0;
}


结果:

the result is 1054592380

相关文章

  • RSA破解

    问题: Alice decides to use RSA with the public key N = 1889...

  • RSA破解

    转载请注明出处:http://www.jianshu.com/p/64dcc0133394 题目: You are...

  • 密码学初见

    最早的密码学: 密码本加密 持续到了上世纪的70年代 RSA加密 只能通过因式分解的方式来破解,破解难度巨大rsa...

  • 简单RSA破解

    问题描述 Alice decides to use RSA with the public key N = 188...

  • bugku rsa wiener attack破解

    rsa wiener attack 破解 当ctf中遇见rsa的n e 都很大而且是同一数量级的,这时候可以采用w...

  • RSA破解作业

    Alice decides to use RSA with the public key N = 18895700...

  • RSA破解作业

    算法思想: 加密过程:c=M^e mod N。解密过程:M=c^d mod N。取c1=2^e mod N,将c和...

  • RSA破解作业

    截至:11月07日23:59提交作业 Alice decides to use RSA with the publ...

  • RSA破解作业

    题目: Alice decides to use RSA with the public key N = 1889...

  • RSA破解作业

    题目 Alice decides to use RSA with the public key N = 18895...

网友评论

      本文标题:RSA破解

      本文链接:https://www.haomeiwen.com/subject/lkurmxtx.html