buuctf RSA3

题目:告诉我们已知c1,e1,n,c2,e2

所以这是一个典型的共模攻击问题,我们需要通过已知的c1和c2来求解答案;

已知:

c1=m^e1 mod n

c2=m^e2 mod n

设存在s1和s2,使情况(c1^s1)*(c2^s2)=(m^(s1*e1))*(m^(s2*e2)) mod n

所以右边计算出为m^(s1*e1+s2*e2) mod n

通过扩展欧几里得算法我们知道,存在s1和s2,使s1*e1+s2*e2=1成立

于是,我们可以通过以上推论,写出代码:

from gmpy2 import invert

import binascii

def gongmo(n, c1, c2, e1, e2):

    def egcd(a, b):

        if b == 0:

            return a, 0

        else:

            x, y = egcd(b, a % b)

            return y, x - (a // b) * y

    s = egcd(e1, e2)

    s1 = s[0]

    s2 = s[1]

    # 求模反元素

    if s1 < 0:

        s1 = - s1

        c1 = invert(c1, n)

    elif s2 < 0:

        s2 = - s2

        c2 = invert(c2, n)

    m = pow(c1, s1, n) * pow(c2, s2, n) % n

    return m

c1=22322035275663237041646893770451933509324701913484303338076210603542612758956262869640822486470121149424485571361007421293675516338822195280313794991136048140918842471219840263536338886250492682739436410013436651161720725855484866690084788721349555662019879081501113222996123305533009325964377798892703161521852805956811219563883312896330156298621674684353919547558127920925706842808914762199011054955816534977675267395009575347820387073483928425066536361482774892370969520740304287456555508933372782327506569010772537497541764311429052216291198932092617792645253901478910801592878203564861118912045464959832566051361

n=22708078815885011462462049064339185898712439277226831073457888403129378547350292420267016551819052430779004755846649044001024141485283286483130702616057274698473611149508798869706347501931583117632710700787228016480127677393649929530416598686027354216422565934459015161927613607902831542857977859612596282353679327773303727004407262197231586324599181983572622404590354084541788062262164510140605868122410388090174420147752408554129789760902300898046273909007852818474030770699647647363015102118956737673941354217692696044969695308506436573142565573487583507037356944848039864382339216266670673567488871508925311154801

e1=11187289

c2=18702010045187015556548691642394982835669262147230212731309938675226458555210425972429418449273410535387985931036711854265623905066805665751803269106880746769003478900791099590239513925449748814075904017471585572848473556490565450062664706449128415834787961947266259789785962922238701134079720414228414066193071495304612341052987455615930023536823801499269773357186087452747500840640419365011554421183037505653461286732740983702740822671148045619497667184586123657285604061875653909567822328914065337797733444640351518775487649819978262363617265797982843179630888729407238496650987720428708217115257989007867331698397

e2=9647291

result = gongmo(n, c1, c2, e1, e2)

print(result)

print(binascii.unhexlify(hex(result)[2:]))

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值