首页 > 其他分享 >DASCTF 2024暑期挑战赛------1z_RSA

DASCTF 2024暑期挑战赛------1z_RSA

时间:2024-07-20 21:07:14浏览次数:12  
标签:10 39 PQ 120 1z RSA 2024 240 79

题目:

from Crypto.Util.number import *
from sympy import *
import os
from secrets import flag

nbit =130
e = 3
l = getPrime(505)
m = bytes_to_long(flag + os.urandom(64))

assert len(flag) == 29

while True:
    p, q = getPrime(nbit), getPrime(nbit)
    PQ = int(str(p<<120)+str(q))
    QP = int(str(q<<120)+str(p))
    if isPrime(PQ) and isPrime(QP):
        break

n = PQ * QP
PP = nextprime((PQ >> 190) * (QP & (2 ** 190 - 1)))
QQ = nextprime((QP >> 190) * (PQ & (2 ** 190 - 1)))
N = PP * QQ
M = pow(m,1,l)
c = pow(m,e,N)

print('n =', n)
print('M =', M)
print('l =', l)
print('c =', c)

'''
n = 18339446336492672809908730785358232636383625709800392830207979464962269419140428722248172110017576390002616004691759163126532392634394976712779777822451878822759056304050545622761060245812934467784888422790178920804822224673755691
M = 36208281423355218604990190624029584747447986456188203264389519699277658026754156377638444926063784368328407938562964768329134840563331354924365667733322
l = 56911058350450672322326236658556745353275014753768458552003425206272938093282425278193278997347671093622024933189270932102361261551908054703317369295189
c = 720286366572443009268610917990845759123049408295363966717060100862857351750759651979922104897091176824666482923148635058966589592286465060161271579501861264957611980854954664798904862706450723639237791023808177615189976108231923
'''

分析代码,需要求出m要得到N的值,那么就得求出PQQP。看一下PQQP的取值方式,知道\(PQ=p*2^{120}*10^{40}+q\)、\(QP=q*2^{120}*10^{39}+p\),所以\(n=PQ*QP=p * q * (2 ^{240} * 10^{79} + 1) + (p^2 + 10 * q^2) * 2^{120} * 10^{39}\),分析一下知道\(2 ^{240} * 10^{79} + 1\)的比特位数大概是503左右,\((p^2 + 10 * q^2) * 2^{120} * 10^{39}\)的比特位数大概是510左右,两者相差不大,那么两边同时除以\(2 ^{240} * 10^{79} + 1\),得\(p*q=n//(2 ^{240} * 10^{79} + 1) \pm x\),这里x的值并不大,可以自行设置个区间进行爆破,那么p*q的值我们是可以知道的,要想求出两个未知数p q还需要知道一个方程才能解出来,我们回到最开始的\(n=PQ*QP=p * q * (2 ^{240} * 10^{79} + 1) + (p^2 + 10 * q^2) * 2^{120} * 10^{39}\),既然我们知道p*q的值我们可以转化一下等式为\(n-p * q * (2 ^{240} * 10^{79} + 1)=(p^2 + 10 * q^2) * 2^{120} * 10^{39}\),化简一下\(p^2 + 10 * q^2=\frac{n-p * q * (2 ^{240} * 10^{79} + 1)}{2^{120}*10^{39}}\),这就是我们第二个方程式了,最后写脚本求出p q注:n - p * q * (2 ^{240} * 10^{79} + 1)必须能被2^{120} * 10^{39}整除

exp:

from sympy import *

n = 18339446336492672809908730785358232636383625709800392830207979464962269419140428722248172110017576390002616004691759163126532392634394976712779777822451878822759056304050545622761060245812934467784888422790178920804822224673755691

for x in range(1500):
    pq=n//(2**240*10**79+1)-x
    if (n-pq*(2**240*10**79+1))%(2**120*10**39)==0:
        p2_q2=(n-pq*(2**240*10**79+1))//(2**120*10**39)
        p=Symbol('p')
        q=Symbol('q')
        pq1=pq-p*q
        pq2=p**2+10*q**2-p2_q2
        s=solve((pq1,pq2))
        print(s)
#p: 1213149261930568621267125437333569321667, q: 855604426214387476576649090490109822073

最后求出N,接下来求解m

\[M=m \pm k*l \rightarrow c=(M \pm k*l)^3\mod N \]

那么我们可以用coppersmith求出k

exp:

from sympy import *

p = 1213149261930568621267125437333569321667
q = 855604426214387476576649090490109822073
PQ = int(str(p<<120)+str(q))
QP = int(str(q<<120)+str(p))
PP = nextprime((PQ >> 190) * (QP & (2 ** 190 - 1)))
QQ = nextprime((QP >> 190) * (PQ & (2 ** 190 - 1)))
N = PP * QQ
#N = 763933528218428362740063144747893290714655295576768532896029874141179804730143020017430379534079773751531037961074867132893544981605022026151484151321515584652838724809597675412676810669583078026377048734720511960708515190930979
#sage
from Crypto.Util.number import *

n = 18339446336492672809908730785358232636383625709800392830207979464962269419140428722248172110017576390002616004691759163126532392634394976712779777822451878822759056304050545622761060245812934467784888422790178920804822224673755691
M = 36208281423355218604990190624029584747447986456188203264389519699277658026754156377638444926063784368328407938562964768329134840563331354924365667733322
l = 56911058350450672322326236658556745353275014753768458552003425206272938093282425278193278997347671093622024933189270932102361261551908054703317369295189
c = 720286366572443009268610917990845759123049408295363966717060100862857351750759651979922104897091176824666482923148635058966589592286465060161271579501861264957611980854954664798904862706450723639237791023808177615189976108231923
N = 763933528218428362740063144747893290714655295576768532896029874141179804730143020017430379534079773751531037961074867132893544981605022026151484151321515584652838724809597675412676810669583078026377048734720511960708515190930979

PR.<x> = PolynomialRing(Zmod(N))
f = c - (M+x*l)^3
f = f.monic()
roots = f.small_roots(X=2^239,epsilon = 0.02)
k = roots[0]
m = M+k*l
print(long_to_bytes(m))
#DASCTF{Ar3_Y0u_Su93_Abt139??}

标签:10,39,PQ,120,1z,RSA,2024,240,79
From: https://www.cnblogs.com/L00kback/p/18313793

相关文章

  • 2024.7.20 模拟赛总结
    T1lcdStatement:给定\(n(1\len\le10^8)\),问有多少对\((i,j)(1\lei,j\len)\)满足\(\frac{xy}{\gcd(x,y)^2}\le3\)。Solution:简单题。令\(x'=\frac{x}{\gcd(x,y)},y'=\frac{y}{\gcd(x,y)}\),枚举\((x',y')\)并计算即可......
  • 20240720周赛订正
    20240720周赛订正总结本场比赛没有任何少拿的分。题解T1尺取。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;//#defineintlonglong#definelcu<<1#definercu<<1|1#definefifirst#definesesecondconstintN=10......
  • 【2024最新版】Vue前端面试篇,看这一篇就够了
    文章目录Vue常用的指令都有哪些v-bind和v-model的区别Vue2的生命周期有哪些Vue3的生命周期有哪些vue3中创建响应式变量的方法ref和reactive原理vuex有哪些方法vue-router生命周期钩子vue框架和原生JavaScript有什么区别对于提升项目加载速度和运行效率是怎么做的webpack......
  • 2024 暑假友谊赛 2
    A题目链接思路:枚举每个十字中心点,合法就标记,最后若还剩下点没被标记就NO#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong#definePIIpair<int,int>constintN=1e6+5,mod=998244353,Mod=1e9+7;intdx[4]={-1,0,1,0};intdy[4......
  • $NOI2024$游记
    day-?~day-?考了期末考后打省队集训,刚开始打的很差,bai了几天状态恢复。打进前4了,好吃捏。$day-1$报道日,育才宿舍真难泵,真独立卫浴,全是蚊子受不了,想不通育才学生一间住八个人怎么活下去的(。育才辣椒不辣,开心!没洗澡,不嘻嘻。day0今年竟是NOI四十周年,dzd英雄人物上位救赎ccf(bu......
  • 2024“钉耙编程”中国大学生算法设计超级联赛(1)结题报告1 2 8
    1001循环位移字符串哈希将a展开*2对于每个长度为len_a的序列进行一次hash存储并将其插入set中对于b进行一次哈希对于每个长度为len_a的连续子串进行一次查询点击查看代码#include<bits/stdc++.h>usingnamespacestd;//22222constintN=5e6+10;constintp1......
  • 2024牛客暑期多校训练营2 解题报告
    B-MST对于整个序列进行一次kruskal对于序列中如果需要访问的点数小于300那么将所有的点的边存入序列中进行kruskal如果大于300那么直接对于所有的点进行kruskal点击查看代码#include<bits/stdc++.h>#defineintlonglong#defineall(x)x.begin(),x.end()#defineral......
  • 国开大学2024《企业法律实务(省开课)》
    5.当事人互负债务,没有先后履行顺序的,应当()A.同时履行B.法院判决C.去法院起诉D.申请仲裁答案:A6.商务谈判法律实务是指企业法务人员在民商事谈判活动中运用()知识,按照商业规则,促成商业交易成就或阻止商业交易成就的行为活动。A.法律   B.商业C.专业D.谈判答案:A7.根据......
  • 2024年IDEA&IntelliJ系列最新激活码(2088)!
    蛋疼ing,仅供学习使用。K384HW36OB-eyJsaWNlbnNlSWQiOiJLMzg0SFczNk9CIiwibGljZW5zZWVOYW1lIjoibWFvIHplZG9uZyIsImxpY2Vuc2VlVHlwZSI6IlBFUlNPTkFMIiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IiIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc2U......
  • 2024年 Intellij IDEA | idea&IDEA系列激活码(持续更新)
       声明:仅供学习使用:K384HW36OB-eyJsaWNlbnNlSWQiOiJLMzg0SFczNk9CIiwibGljZW5zZWVOYW1lIjoibWFvIHplZG9uZyIsImxpY2Vuc2VlVHlwZSI6IlBFUlNPTkFMIiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IiIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc......