【rsa】低指数相关消息攻击

https://link.springer.com/content/pdf/10.1007/3-540-68339-9_1.pdf

python 复制代码
from Crypto.Util.number import *
import binascii
import gmpy2
flag = '*****************************************'
hex_flag=int(flag.encode("hex"),16)

p=getPrime(256)
q=getPrime(256)
n=p*q

e=0x3
c1=pow(hex_flag,e,n)
c2=pow(hex_flag+1,e,n)


print("n=",hex(n))
print("e=",hex(e))
print("c1=",hex(c1))
print("c2=",hex(c2))

'''
('n=', '0xb28ae8f29f8b90e8b8c5667b2b71e49929446b41f7f7a3e9e45bc52a1e8c45d59c1788be48a9c365d51feee0b2cd3295001cdad1ba5ccf808686b5ce5a269ae5L')
('e=', '0x3')
('c1=', '0x7ba5502ecbc3b15ad8c2db8f30a593eb062dde4d7dfacadf0a28291d1a576389a18dfba0607c0243f843f637449089dd2090d47ee9845d4147f02afd4d891f19L')
('c2=', '0x891ac4f663df41c1f6433ee3513d749c3ba02fe0aacd7f51d791b9bac4f7e5194bd484d78d972c344faf600f7d3aa580485774768efc47ab8ddb67eeeb330fa1L')
'''

solve

python 复制代码
#!/usr/bin/python
# -*- coding: utf-8 -*-
import gmpy2

n = 9351035609579912430580224362406913775216485260866801060250235841497131649675821473038044490729550589638048144137033269711790417615294506088800324197718757
e = 3
c1 =6475853636479050645596496086080582816789963066323389815672770714308619633711541909793891052802547415987144453383534840748034987689956953991901404774080281
c2 =7180748878269451580223627474056868509561249251375351465737365567454518806786657134253453800373864987758778056252628950652794949518011402960483137799524257

def related_messages(a, b, c1, c2, n):
    a3 = pow(a, 3, n)
    b3 = pow(b, 3, n)
    mpoly = ((c2 + 2*a3*c1 - b3) * b) % n
    poly = ((c2 - a3*c1 + 2*b3) * a) % n
    tmp3 = gmpy2.invert(poly, n)
    m = (mpoly * tmp3) % n
    return m

m = related_messages(1, 1, c1, c2, n)
print(bytes.fromhex(hex(m)[2:]))
#b'flag is :3e7f54b8ad38787670776c2698a67c01'
相关推荐
梧桐树04293 小时前
python常用内建模块:collections
python
Dream_Snowar3 小时前
速通Python 第三节
开发语言·python
蓝天星空5 小时前
Python调用open ai接口
人工智能·python
jasmine s5 小时前
Pandas
开发语言·python
郭wes代码5 小时前
Cmd命令大全(万字详细版)
python·算法·小程序
leaf_leaves_leaf5 小时前
win11用一条命令给anaconda环境安装GPU版本pytorch,并检查是否为GPU版本
人工智能·pytorch·python
夜雨飘零15 小时前
基于Pytorch实现的说话人日志(说话人分离)
人工智能·pytorch·python·声纹识别·说话人分离·说话人日志
404NooFound5 小时前
Python轻量级NoSQL数据库TinyDB
开发语言·python·nosql
天天要nx5 小时前
D102【python 接口自动化学习】- pytest进阶之fixture用法
python·pytest
minstbe5 小时前
AI开发:使用支持向量机(SVM)进行文本情感分析训练 - Python
人工智能·python·支持向量机