首页 > 其他分享 >DASCTF-Crypto-Sign1n

DASCTF-Crypto-Sign1n

时间:2023-04-22 20:22:31浏览次数:47  
标签:phi gmpy2 Crypto times WHATF add Sign1n DASCTF

sign1n

显然能导出下面的式子:

\(k\times phi = e^3\times (WHATF - 3) - 1\).

注意到\(phi = (p-1)\times(q-1)=n-(p+q)+1\), \(n=p\times q\).

考虑构造一元二次方程解出pq.

同时考虑到\(k\times(p+q-1)<n\),代入得到:

\(k\times(p+q-1) = (1 - e^3\times(WHATF - 3)) \mod n\).

这边就能通过GCD得到系数k, 从而得到p + q.

exp:

from Crypto.Util.number import *
import gmpy2
n = 17501785470905115084530641937586010443633001681612179692218171935474388105810758340844015368385708349722992595891293984847291588862799310921139505076364559140770828784719022502905431468825797666445114531707625227170492272392144861677408547696040355055483067831733807927267488677560035243230884564063878855983123740667214237638766779250729115967995715398679183680360515620300448887396447013941026492557540060990171678742387611013736894406804530109193638867704765955683067309269778890269186100476308998155078252336943147988308936856121869803970807195714727873626949774272831321358988667427984601788595656519292763705699
WHATF = 7550872408895903340469549867088737779221735042983487867888690747510707575208917229455135563614675077641314504029666714424242441219246566431788414277587183624484845351111624500646035107614221756706581150918776828118482092241867365644233950852801286481603893259029733993572417125002284605243126366683373762688802313288572798197775563793405251353957529601737375987762230223965539018597115373258092875512799931693493522478726661976059512568029782074142871019609980899851702029278565972205831732184397965899892253392769838212803823816067145737697311648549879049613081017925387808738647333178075446683195899683981412014732
sign = 12029865785359077271888851642408932941748698222400692402967271078485911077035193062225857653592806498565936667868784327397659271889359852555292426797695393591842279629975530499882434299824406229989496470187187565025826834367095435441393901750671657454855301104151016192695436071059013094114929109806658331209302942624722867961155156665675500638029626815869590842939369327466155186891537025880396861428410389552502395963071259114101340089657190695306100646728391832337848064478382298002033457224425654731106858054291015385823564302151351406917158392454536296555530524352049490745470215338669859669599380477470525863815

e = 0x10001

k_phi = e**3 * (WHATF - 3) - 1  # k*phi
k_p_add_q_1 = (1 - e**3 * (WHATF - 3)) % n  # k*(p+q-1)
k = GCD(k_phi, k_p_add_q_1)
p_add_q = k_p_add_q_1 // k + 1
assert gmpy2.iroot(p_add_q**2 - 4 * n, 2)[1]
delta = gmpy2.iroot(p_add_q**2 - 4 * n, 2)[0]
p = (p_add_q + delta) // 2
q = p_add_q - p
assert p*q == n
print(f"p = {p}\nq = {q}")

phi = (p-1) * (q-1)
d = inverse(e, phi)
m = pow(sign, e, n)

这边r试了一个2就出了:

r = 2
d = gmpy2.invert(e, phi)
c = gmpy2.invert(pow(r, e**2+d**2, n), n)
print(long_to_bytes(m*c % n))

flag: DASCTF{RSA_Bl1nd_Signatur3_With_M4th}

标签:phi,gmpy2,Crypto,times,WHATF,add,Sign1n,DASCTF
From: https://www.cnblogs.com/Lovechan/p/17343828.html

相关文章

  • 【win10】No module named “Crypto”
    1、问题  下载视频解析的时候报错Nomodulenamed“Crypto”,已经pip安装  2、解决pipuninstallcryptopycryptodomepipinstallpycryptodome pycrypto和crypto是同一个库,crypto在python中又被称为pycrypto,它是一个第三方库,但是已经停止更新了,所以不建议大......
  • Proj. CHW Paper Reading: Characterizing Cryptocurrency Exchange Scams
    1.introBlockchaincommunity防范scamattack措施包含maliciousdomains的开源数据库,例如CryptoScamDB和EtherScanDB多半是使用crowd-sourcingbasedapproach搜集,例如受害者报告本文探究theextentthescamsexistintheecosystemwhoaretheattackerswhatare......
  • Buuctf刷题Crypto 5day
    1、[WUSTCTF2020]佛说:只能四天先看题目,给了三个文件:尊即寂修我劫修如婆愍闍嚤婆莊愍耨羅嚴是喼婆斯吶眾喼修迦慧迦嚩喼斯願嚤摩隸所迦摩吽即塞願修咒莊波斯訶喃壽祗僧若即亦嘇蜜迦須色喼羅囉咒諦若陀喃慧愍夷羅波若劫蜜斯哆咒塞隸蜜波哆咤慧聞亦吽念彌諸嘚嚴諦咒陀叻咤叻諦缽隸祗......
  • jsencrypt与sm-crypto对url加解密处理
    1.jsencrypt公钥私钥随便找个网站生成(https://www.bejson.com/enc/rsa/)1.安装包:npmijsencrypt--save2.封装函数import{JSEncrypt}from'jsencrypt';//加密msg为需要加密的字符串,返回加密后的字符串exportfunctionsetEncrypt(msg){constjsencrypt=newJS......
  • windows环境下python3安装Crypto
    pycrypto、pycrytodome和crypto是一个东西,crypto在python上面的名字是pycrypto,它是一个第三方库,但是已经停止更新三年了,所以不建议安装这个库;这个时候pycryptodome就来了,它是pycrypto的延伸版本,用法和pycrypto是一模一样的;所以,我现在告诉大家一种解决方法--直接安装:pipinstallpy......
  • UVa 113 / POJ 2109 Power of Cryptography (使用double处理大整数&泰勒公式与误差分
    113-PowerofCryptographyTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=49http://poj.org/problem?id=2109题意:给出n和p,求出 ,但是p可以很大()如何存储p?不用大数可不可以?先看看double......
  • JSON.parse意外失败的问题(传入内容在校验网站上检查无误)(传入内容来自CryptoJS.AES.dec
    背景:由CryptoJS.AES.decrypt解码来的数据并进行toString(CryptoJS.enc.Utf8)之后,无法使用JSON.parse转换成json数据,但是使用在线校验工具认为格式正确。可能是由于解码后的字符串包含了一些特殊字符或者不可见字符,导致JSON.parse方法无法正确解析字符串。可以尝试使用console.log......
  • buuctf.crypto.NCTF2019]childRSA
    预期解法Pollard'sp-1method题目fromrandomimportchoicefromCrypto.Util.numberimportisPrime,sieve_baseasprimesfromflagimportflagdefgetPrime(bits):whileTrue:n=2whilen.bit_length()<bits:n*=cho......
  • 密码学分析-工具——CryptoSMT
     CryptoSMT是一个易于使用的工具,用于对称原语的密码分析,如分组密码或哈希函数。它基于SMT/SAT求解器,如STP,Boolector,CryptoMiniSat,并提供了一个简单的框架来使用它们进行密码分析技术。 其中一些特点是: *关于原语微分行为的证明性质。 *寻找最佳的线性/微分路......
  • Coinc1dens's lessons for cryptography beginner
    Coinc1dens'slessonsforcryptographybeginner10分题懒得写,赛后浅写一下(有些还真写不出来)太屑了古典懒得写,相信都写的出来1.childexgcdi即为m在模p情况下的乘法逆......