您的位置:首页 > 其它

BUUCTF Crypto SameMod wp

2020-04-22 00:15 1051 查看

这道题一看题目SameMod就可以猜到是RSA中的共模攻击
关于共模攻击的原理这里就不多赘述了,可以参考ctfwiki
https://wiki.x10sec.org/crypto/asymmetric/rsa/rsa_module_attack
下面直接给出本题脚本

// python2
from gmpy2 import invert
def gongmogongji(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

n= 6266565720726907265997241358331585417095726146341989755538017122981360742813498401533594757088796536341941659691259323065631249
e1= 773
e2= 839
c1= 3453520592723443935451151545245025864232388871721682326408915024349804062041976702364728660682912396903968193981131553111537349
c2= 5672818026816293344070119332536629619457163570036305296869053532293105379690793386019065754465292867769521736414170803238309535

result = gongmogongji(n, c1, c2, e1, e2)
print(result)
#1021089710312311910410111011910111610410511010710511610511511211111511510598108101125
#flag=hex(result)[2:].decode('hex')
result=str(result)
flag=""
i=0
while i < len(result):
if result[i]=='1':
c=chr(int(result[i:i+3]))
i+=3
else:
c=chr(int(result[i:i+2]))
i+=2
flag+=c
print(flag)
#flag{whenwethinkitispossible}

做这题的时候一开始想到是将明文进行hex的,试了一下发现不对,才通过ascii的方式解得,flag需要是可见字符,所以不存在1开头的十位数,所以1开头的肯定是100以上的三位数,由此可解得flag

  • 点赞
  • 收藏
  • 分享
  • 文章举报
唏嘘的羊腰子 发布了28 篇原创文章 · 获赞 1 · 访问量 1338 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: