【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'
相关推荐
DanielYQ32 分钟前
LCR 001 两数相除
开发语言·python·算法
vener_1 小时前
LuckySheet协同编辑后端示例(Django+Channel,Websocket通信)
javascript·后端·python·websocket·django·luckysheet
封步宇AIGC1 小时前
量化交易系统开发-实时行情自动化交易-4.2.3.指数移动平均线实现
人工智能·python·机器学习·数据挖掘
互联网杂货铺1 小时前
自动化测试基础知识总结
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
小汤猿人类1 小时前
SpringTask
开发语言·python
网络安全(king)2 小时前
【Python】【持续项目】Python-安全项目搜集
开发语言·python·安全
工业甲酰苯胺2 小时前
Python脚本消费多个Kafka topic
开发语言·python·kafka
做程序员的第一天3 小时前
在PyTorch中,钩子(hook)是什么?在神经网络中扮演什么角色?
pytorch·python·深度学习
yyywxk3 小时前
VSCode 新建 Python 包/模块 Pylance 无法解析
ide·vscode·python
Nerinic3 小时前
PyTorch基础2
pytorch·python