EZmath

题目如下

点击查看代码
#sage9.3
from Crypto.Util.number import *
flag = b'Kicky_Mu{KFC_v_me_50!!!}'
p = getPrime(256)
q = getPrime(256)
n = p*q^3
e = 65537
N = pow(p, 2) + pow(q, 2)
m = bytes_to_long(flag)
c = pow(m,e,n)

print(c)
print(N)


# c = 34992437145329058006346797890363070594973075282993832268508442432592383794878795192132088668900695623924153165395583430068203662437982480669703879475321408183026259569199414707773374072930515794134567251046302713509056391105776219609788157691337060835717732824405538669820477381441348146561989805141829340641
# N = 14131431108308143454435007577716000559419205062698618708133959457011972529354493686093109431184291126255192573090925119389094648901918393503865225710648658

总结:

对sage掌握的太生疏了qaq
刚开始进行了一系列的数学推导,发现无济于事,然后问了gpt,gpt的回答误导了我很长时间!!!!!!!!!!!!(我再也不会相信人工智能)
好了,本题关键在于\(N = p^2 + q^2\)
了解到sage中有:已知平方和可以直接分解出两个因子的语句---two_squares()
这个语句的使用原理[https://wstein.org/edu/2007/spring/ent/ent-html/node75.html]
原谅我看不太懂。。。,等我看懂了把这一块补上
用sage把N分解后写python
所以我们给一个python的脚本

点击查看代码

from Crypto.Util.number import *
import gmpy2

p = 82560919832754349126354116140838623696638559109075709234619471489244325313113
q = 85528507672457684655471526239900307861713918212607409966382024323034858694833
c = 34992437145329058006346797890363070594973075282993832268508442432592383794878795192132088668900695623924153165395583430068203662437982480669703879475321408183026259569199414707773374072930515794134567251046302713509056391105776219609788157691337060835717732824405538669820477381441348146561989805141829340641
n = p * q**3
e = 65537

phi = q**2 * (p-1 )* (q - 1)   #  phi(k*n) = k * phi(n)
d = gmpy2.invert(e , phi)
print(long_to_bytes(pow(c, d, n )))
ok,运行得到flag$b'H&NCTF{D0_Y0u_know_Complex_n3mbers?hahaha}'$
posted @ 2024-05-14 19:01  附体欢欢  阅读(8)  评论(0编辑  收藏  举报