5.6-5.12一周学习记录

5.6-5.12周报

1.funnyrsa2:n分解多素数

from Crypto.Util.number import getPrime
import libnum
from secret import flag

e = 0x10001
p = getPrime(80)
q = getPrime(80)
r = getPrime(80)
n = p * q * r
m = libnum.s2n(flag)
c = pow(m,e,n)
print("n =", n)
print("c =", c)
# n = 897607935780955837078784515115186203180822213482989041398073067996023639
# c = 490571531583321382715358426750276448536961994273309958885670149895389968

分析题目:

n是由p,q,r三个数相乘得到的,可以先尝试分解n:

得到:
在这里插入图片描述

phi_n也可以计算出来,常规计算即可:

import gmpy2
from Crypto.Util.number import long_to_bytes
import libnum

e = 0x10001
n = 897607935780955837078784515115186203180822213482989041398073067996023639
c = 490571531583321382715358426750276448536961994273309958885670149895389968
p = 876391552113414716726089
q = 932470255754103340237147
r = 1098382268985762240184333

phi_n=(p-1)*(q-1)*(r-1)
d=gmpy2.invert(e,phi_n)
m=gmpy2.powmod(c,d,n)
print(long_to_bytes(m))
#b'flag{what_that_fvck_r}'

2.funnyrsa3:dp泄露

e = 65537
n = 13851998696110232034312408768370264747862778787235362033287301947690834384177869107768578977872169953363148442670412868565346964490724532894099772144625540138618913694240688555684873934424471837897053658485573395777349902581306875149677867098014969597240339327588421766510008083189109825385296069501377605893298996953970043168244444585264894721914216744153344106498382558756181912535774309211692338879110643793628550244212618635476290699881188640645260075209594318725693972840846967120418641315829098807385382509029722923894508557890331485536938749583463709142484622852210528766911899504093351926912519458381934550361
dp = 100611735902103791101540576986246738909129436434351921338402204616138072968334504710528544150282236463859239501881283845616704984276951309172293190252510177093383836388627040387414351112878231476909883325883401542820439430154583554163420769232994455628864269732485342860663552714235811175102557578574454173473
c = 6181444980714386809771037400474840421684417066099228619603249443862056564342775884427843519992558503521271217237572084931179577274213056759651748072521423406391343404390036640425926587772914253834826777952428924120724879097154106281898045222573790203042535146780386650453819006195025203611969467741808115336980555931965932953399428393416196507391201647015490298928857521725626891994892890499900822051002774649242597456942480104711177604984775375394980504583557491508969320498603227402590571065045541654263605281038512927133012338467311855856106905424708532806690350246294477230699496179884682385040569548652234893413

分析题目:

题中给了e,n,dp,c,为之前所见过的dp泄露,套脚本

import gmpy2
e = 65537
n = 13851998696110232034312408768370264747862778787235362033287301947690834384177869107768578977872169953363148442670412868565346964490724532894099772144625540138618913694240688555684873934424471837897053658485573395777349902581306875149677867098014969597240339327588421766510008083189109825385296069501377605893298996953970043168244444585264894721914216744153344106498382558756181912535774309211692338879110643793628550244212618635476290699881188640645260075209594318725693972840846967120418641315829098807385382509029722923894508557890331485536938749583463709142484622852210528766911899504093351926912519458381934550361
dp = 100611735902103791101540576986246738909129436434351921338402204616138072968334504710528544150282236463859239501881283845616704984276951309172293190252510177093383836388627040387414351112878231476909883325883401542820439430154583554163420769232994455628864269732485342860663552714235811175102557578574454173473
c = 6181444980714386809771037400474840421684417066099228619603249443862056564342775884427843519992558503521271217237572084931179577274213056759651748072521423406391343404390036640425926587772914253834826777952428924120724879097154106281898045222573790203042535146780386650453819006195025203611969467741808115336980555931965932953399428393416196507391201647015490298928857521725626891994892890499900822051002774649242597456942480104711177604984775375394980504583557491508969320498603227402590571065045541654263605281038512927133012338467311855856106905424708532806690350246294477230699496179884682385040569548652234893413

for i in range(1, e):  # 在范围(1,e)之间进行遍历
    if (dp * e - 1) % i == 0:
        if n % (((dp * e - 1) // i) + 1) == 0:  # 存在p,使得n能被p整除
            p = ((dp * e - 1) // i) + 1
            q = n // (((dp * e - 1) // i) + 1)
            phi = (q - 1) * (p - 1)  # 欧拉定理
            d = gmpy2.invert(e, phi)  # 求模逆
            m = pow(c, d, n)  # 快速求幂取模运算
print(bytes.fromhex(hex(m)[2:]))  # 16进制转文本
#b'b'flag{dp_i5_1eak}'

3.unusualrsa1:高位攻击

from Crypto.Util.number import getPrime,bytes_to_long,long_to_bytes
from random import randint
from secret import flag

p = getPrime(1024)
q = getPrime(1024)
n = p*q
print(n)

m = bytes_to_long(long_to_bytes(randint(0,30))*208+flag)
assert(m.bit_length()==2044)
print((m>>315)<<315)
c = pow(m,3,n)
print(c)

#14113948189208713011909396304970377626324044633561155020366406284451614054260708934598840781397326960921718892801653205159753091559901114082556464576477585198060530094478860626532455065960136263963965819002575418616768412539016154873800614138683106056209070597212668250136909436974469812231498651367459717175769611385545792201291192023843434476550550829737236225181770896867698281325858412643953550465132756142888893550007041167700300621499970661661288422834479368072744930285128061160879720771910458653611076539210357701565156322144818787619821653007453741709031635862923191561438148729294430924288173571196757351837
#1520800285708753284739523608878585974609134243280728660335545667177630830064371336150456537012842986526527904043383436211487979254140749228004148347597566264500276581990635110200009305900689510908049771218073767918907869112593870878204145615928290375086195098919355531430003571366638390993296583488184959318678321571278510231561645872308920917404996519309473979203661442792048291421574603018835698487725981963573816645574675640357569465990665689618997534740389987351864738104038598104713275375385003471306823348792559733332094774873827383320058176803218213042061965933143968710199376164960850951030741280074168795136
#6635663565033382363211849843446648120305449056573116171933923595209656581213410699649926913276685818674688954045817246263487415328838542489103709103428412175252447323358040041217431171817865818374522191881448865227314554997131690963910348820833080760482835650538394814181656599175839964284713498394589419605748581347163389157651739759144560719049281761889094518791244702056048080280278984031050608249265997808217512349309696532160108250480622956599732443714546043439089844571655280770141647694859907985919056009576606333143546094941635324929407538860140272562570973340199814409134962729885962133342668270226853146819

分析代码:

(m>>315)<<315可知m先向右移315位,再向左移315位,与我上周做的题一样,都为coppersmith,不过这道题是已知m高位,那就用sagemath推一下,kbits为315:

在这里插入图片描述

import gmpy2
from Crypto.Util.number import getPrime,bytes_to_long,long_to_bytes
from random import randint
n=14113948189208713011909396304970377626324044633561155020366406284451614054260708934598840781397326960921718892801653205159753091559901114082556464576477585198060530094478860626532455065960136263963965819002575418616768412539016154873800614138683106056209070597212668250136909436974469812231498651367459717175769611385545792201291192023843434476550550829737236225181770896867698281325858412643953550465132756142888893550007041167700300621499970661661288422834479368072744930285128061160879720771910458653611076539210357701565156322144818787619821653007453741709031635862923191561438148729294430924288173571196757351837
m_high=1520800285708753284739523608878585974609134243280728660335545667177630830064371336150456537012842986526527904043383436211487979254140749228004148347597566264500276581990635110200009305900689510908049771218073767918907869112593870878204145615928290375086195098919355531430003571366638390993296583488184959318678321571278510231561645872308920917404996519309473979203661442792048291421574603018835698487725981963573816645574675640357569465990665689618997534740389987351864738104038598104713275375385003471306823348792559733332094774873827383320058176803218213042061965933143968710199376164960850951030741280074168795136
c=6635663565033382363211849843446648120305449056573116171933923595209656581213410699649926913276685818674688954045817246263487415328838542489103709103428412175252447323358040041217431171817865818374522191881448865227314554997131690963910348820833080760482835650538394814181656599175839964284713498394589419605748581347163389157651739759144560719049281761889094518791244702056048080280278984031050608249265997808217512349309696532160108250480622956599732443714546043439089844571655280770141647694859907985919056009576606333143546094941635324929407538860140272562570973340199814409134962729885962133342668270226853146819
e=3
'''
kbits=315
PR.<x> = PolynomialRing(Zmod(n))
f = (m_high + x)^e - c
x0 = f.small_roots(2^kbits,1)[0]
m = m_high + x0
print(m)
'''
m=1520800285708753284739523608878585974609134243280728660335545667177630830064371336150456537012842986526527904043383436211487979254140749228004148347597566264500276581990635110200009305900689510908049771218073767918907869112593870878204145615928290375086195098919355531430003571366638390993296583488184959318678321571278510231561645872308920917404996519309473979203661442792048291421574603018835698487725981963573816645574675640357569465990665689618997534740389987351864738104038598104713275375385003471306823348792559733393609593321367463114703873343853590413300366406780333184299791982772652326424221774382732443261
print(long_to_bytes(m))
#b'\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0cflag{r54__c0pp3r5m17h_p4r714l_m_4774ck_15_c00l~}'

4.unusualrsa2:Related Message Attack含线性关系

参考:http://t.csdnimg.cn/ln4ab

from Crypto.Util.number import getPrime,bytes_to_long,long_to_bytes
from functools import reduce
from secret import flag, x, y

m = bytes_to_long(flag)
p = getPrime(1024)
q = getPrime(1024)
n = p*q
print(n)

assert(reduce(lambda x,y:x&y,[(i-5)*i+6==0 for i in x]))
assert(reduce(lambda x,y:x&y,[(j-15)*j+44==0 for j in y]))

print(pow(reduce(lambda x,y:x*m+y,x),17,n))
print(pow(reduce(lambda x,y:x*m+y,y),17,n))

#23772599983135215481563178266884362291876571759991288577057472733374903836591330410574958472090396886895304944176208711481780781286891334062794555288959410390926474473859289842654809538435377431088422352076225067494924657598298955407771484146155998883073439266427190212827600119365643065276814044272790573450938596830336430371987561905132579730619341196199420897034988685012777895002554746080384319298123154671447844799088258541911028041717897434816921424155687677867019535399434825468160227242441375503664915265223696139025407768146464383537556265875013085702422829200814612395116961538432886116917063119749068212699
#10900151504654409767059699202929100225155892269473271859207513720755903691031362539478242920144073599515746938827937863835169270383721094542639011665235593065932998091574636525973099426040452626893461449084383663453549354608769727777329036059746386523843912382289597182615339786437186169811342356085836838520978047561127661777189045888648773949147220411427306098338616422692914110656004863767719312410906124366000507952960331116878197129010412361636679449281808407214524741732730279777729251515759320442591663641984363061618865267606007355576230009922421807527598213455112981354590909603317525854070358390622096569841
#17298679220717326374674940612143058330715465693318467692839033642321129433471254547497087746971317567301086124779289015934582615377165560688447452762043163082394944604062014490446763247008217251611443338103074143809936437694543761369945095202092750900940979469994907399829695696313513303922266742415376818434932335640062684245008822643258497589196668426788916969378417960200705779461808292296450298558001909603602502604228973101048082095642290047196235959438278631661658312398313171590515776453711432353011579809351076532129444735206408591345372296372378396539831385036814349328459266432393612919118094115543053115450

这个题涉及到了新的题型,首先了解一下题目:

已知n,还给出了关于i,j的方程组,(i-5)*i+60以及(j-15)*j+440。

先来了解一下reduce函数:reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。

reduce() 可以作为一个高阶函数,用于函数的 compose。

那么先求一下i,j:

i1=2,i2=3

j1=4,j2=11

带入到两个lambda表达式中:得到x=[2,3],y=[4,11]

reduce(lambda x,y:x*m+y,x)→2m+3

reduce(lambda x,y:x*m+y,y)→4m+11

所以得到了关于m的两个关系式,那么打印出来的即为c

c1=(2m+3)^17 mod n

c2=(4m+11)^17 mod n

由此,题目已知了n,e,以及两个c,该题仍需用sagemath解题,代入脚本:

#sage
import binascii
c1 = 10900151504654409767059699202929100225155892269473271859207513720755903691031362539478242920144073599515746938827937863835169270383721094542639011665235593065932998091574636525973099426040452626893461449084383663453549354608769727777329036059746386523843912382289597182615339786437186169811342356085836838520978047561127661777189045888648773949147220411427306098338616422692914110656004863767719312410906124366000507952960331116878197129010412361636679449281808407214524741732730279777729251515759320442591663641984363061618865267606007355576230009922421807527598213455112981354590909603317525854070358390622096569841
c2 = 17298679220717326374674940612143058330715465693318467692839033642321129433471254547497087746971317567301086124779289015934582615377165560688447452762043163082394944604062014490446763247008217251611443338103074143809936437694543761369945095202092750900940979469994907399829695696313513303922266742415376818434932335640062684245008822643258497589196668426788916969378417960200705779461808292296450298558001909603602502604228973101048082095642290047196235959438278631661658312398313171590515776453711432353011579809351076532129444735206408591345372296372378396539831385036814349328459266432393612919118094115543053115450
n = 23772599983135215481563178266884362291876571759991288577057472733374903836591330410574958472090396886895304944176208711481780781286891334062794555288959410390926474473859289842654809538435377431088422352076225067494924657598298955407771484146155998883073439266427190212827600119365643065276814044272790573450938596830336430371987561905132579730619341196199420897034988685012777895002554746080384319298123154671447844799088258541911028041717897434816921424155687677867019535399434825468160227242441375503664915265223696139025407768146464383537556265875013085702422829200814612395116961538432886116917063119749068212699
e = 17

def attack(c1, c2, n, e):
    PR.<x>= PolynomialRing(Zmod(n))
    # replace a,b,c,d
    g1 = (2 * x + 3) ^ e - c1
    g2 = (4 * x + 11) ^ e - c2

    def gcd(g1, g2):
        while g2:
            g1, g2 = g2, g1 % g2
        return g1.monic()

    return -gcd(g1, g2)[0]

m1 = attack(c1, c2, n, e)
print(binascii.unhexlify("%x" % int(m1)))

在这里插入图片描述

5.unusualrsa5:n,c不可分解多项式

题目给出了p,n,e,c,但n,c都是多项式,参考脚本

#sage
from gmpy2 import *
 
p = 2470567871
R.<x> = PolynomialRing(GF(p))  # 构造以p为模的,关于x的多项式
N = 1932231392 * x ^ 255 + 1432733708 * x ^ 254 + 1270867914 * x ^ 253 + 1573324635 * x ^ 252 + 2378103997 * x ^ 251 + 820889786 * x ^ 250 + 762279735 * x ^ 249 + 1378353578 * x ^ 248 + 1226179520 * x ^ 247 + 657116276 * x ^ 246 + 1264717357 * x ^ 245 + 1015587392 * x ^ 244 + 849699356 * x ^ 243 + 1509168990 * x ^ 242 + 2407367106 * x ^ 241 + 873379233 * x ^ 240 + 2391647981 * x ^ 239 + 517715639 * x ^ 238 + 828941376 * x ^ 237 + 843708018 * x ^ 236 + 1526075137 * x ^ 235 + 1499291590 * x ^ 234 + 235611028 * x ^ 233 + 19615265 * x ^ 232 + 53338886 * x ^ 231 + 434434839 * x ^ 230 + 902171938 * x ^ 229 + 516444143 * x ^ 228 + 1984443642 * x ^ 227 + 966493372 * x ^ 226 + 1166227650 * x ^ 225 + 1824442929 * x ^ 224 + 930231465 * x ^ 223 + 1664522302 * x ^ 222 + 1067203343 * x ^ 221 + 28569139 * x ^ 220 + 2327926559 * x ^ 219 + 899788156 * x ^ 218 + 296985783 * x ^ 217 + 1144578716 * x ^ 216 + 340677494 * x ^ 215 + 254306901 * x ^ 214 + 766641243 * x ^ 213 + 1882320336 * x ^ 212 + 2139903463 * x ^ 211 + 1904225023 * x ^ 210 + 475412928 * x ^ 209 + 127723603 * x ^ 208 + 2015416361 * x ^ 207 + 1500078813 * x ^ 206 + 1845826007 * x ^ 205 + 797486240 * x ^ 204 + 85924125 * x ^ 203 + 1921772796 * x ^ 202 + 1322682658 * x ^ 201 + 2372929383 * x ^ 200 + 1323964787 * x ^ 199 + 1302258424 * x ^ 198 + 271875267 * x ^ 197 + 1297768962 * x ^ 196 + 2147341770 * x ^ 195 + 1665066191 * x ^ 194 + 2342921569 * x ^ 193 + 1450622685 * x ^ 192 + 1453466049 * x ^ 191 + 1105227173 * x ^ 190 + 2357717379 * x ^ 189 + 1044263540 * x ^ 188 + 697816284 * x ^ 187 + 647124526 * x ^ 186 + 1414769298 * x ^ 185 + 657373752 * x ^ 184 + 91863906 * x ^ 183 + 1095083181 * x ^ 182 + 658171402 * x ^ 181 + 75339882 * x ^ 180 + 2216678027 * x ^ 179 + 2208320155 * x ^ 178 + 1351845267 * x ^ 177 + 1740451894 * x ^ 176 + 1302531891 * x ^ 175 + 320751753 * x ^ 174 + 1303477598 * x ^ 173 + 783321123 * x ^ 172 + 1400145206 * x ^ 171 + 1379768234 * x ^ 170 + 1191445903 * x ^ 169 + 946530449 * x ^ 168 + 2008674144 * x ^ 167 + 2247371104 * x ^ 166 + 1267042416 * x ^ 165 + 1795774455 * x ^ 164 + 1976911493 * x ^ 163 + 167037165 * x ^ 162 + 1848717750 * x ^ 161 + 573072954 * x ^ 160 + 1126046031 * x ^ 159 + 376257986 * x ^ 158 + 1001726783 * x ^ 157 + 2250967824 * x ^ 156 + 2339380314 * x ^ 155 + 571922874 * x ^ 154 + 961000788 * x ^ 153 + 306686020 * x ^ 152 + 80717392 * x ^ 151 + 2454799241 * x ^ 150 + 1005427673 * x ^ 149 + 1032257735 * x ^ 148 + 593980163 * x ^ 147 + 1656568780 * x ^ 146 + 1865541316 * x ^ 145 + 2003844061 * x ^ 144 + 1265566902 * x ^ 143 + 573548790 * x ^ 142 + 494063408 * x ^ 141 + 1722266624 * x ^ 140 + 938551278 * x ^ 139 + 2284832499 * x ^ 138 + 597191613 * x ^ 137 + 476121126 * x ^ 136 + 1237943942 * x ^ 135 + 275861976 * x ^ 134 + 1603993606 * x ^ 133 + 1895285286 * x ^ 132 + 589034062 * x ^ 131 + 713986937 * x ^ 130 + 1206118526 * x ^ 129 + 311679750 * x ^ 128 + 1989860861 * x ^ 127 + 1551409650 * x ^ 126 + 2188452501 * x ^ 125 + 1175930901 * x ^ 124 + 1991529213 * x ^ 123 + 2019090583 * x ^ 122 + 215965300 * x ^ 121 + 532432639 * x ^ 120 + 1148806816 * x ^ 119 + 493362403 * x ^ 118 + 2166920790 * x ^ 117 + 185609624 * x ^ 116 + 184370704 * x ^ 115 + 2141702861 * x ^ 114 + 223551915 * x ^ 113 + 298497455 * x ^ 112 + 722376028 * x ^ 111 + 678813029 * x ^ 110 + 915121681 * x ^ 109 + 1107871854 * x ^ 108 + 1369194845 * x ^ 107 + 328165402 * x ^ 106 + 1792110161 * x ^ 105 + 798151427 * x ^ 104 + 954952187 * x ^ 103 + 471555401 * x ^ 102 + 68969853 * x ^ 101 + 453598910 * x ^ 100 + 2458706380 * x ^ 99 + 889221741 * x ^ 98 + 320515821 * x ^ 97 + 1549538476 * x ^ 96 + 909607400 * x ^ 95 + 499973742 * x ^ 94 + 552728308 * x ^ 93 + 1538610725 * x ^ 92 + 186272117 * x ^ 91 + 862153635 * x ^ 90 + 981463824 * x ^ 89 + 2400233482 * x ^ 88 + 1742475067 * x ^ 87 + 437801940 * x ^ 86 + 1504315277 * x ^ 85 + 1756497351 * x ^ 84 + 197089583 * x ^ 83 + 2082285292 * x ^ 82 + 109369793 * x ^ 81 + 2197572728 * x ^ 80 + 107235697 * x ^ 79 + 567322310 * x ^ 78 + 1755205142 * x ^ 77 + 1089091449 * x ^ 76 + 1993836978 * x ^ 75 + 2393709429 * x ^ 74 + 170647828 * x ^ 73 + 1205814501 * x ^ 72 + 2444570340 * x ^ 71 + 328372190 * x ^ 70 + 1929704306 * x ^ 69 + 717796715 * x ^ 68 + 1057597610 * x ^ 67 + 482243092 * x ^ 66 + 277530014 * x ^ 65 + 2393168828 * x ^ 64 + 12380707 * x ^ 63 + 1108646500 * x ^ 62 + 637721571 * x ^ 61 + 604983755 * x ^ 60 + 1142068056 * x ^ 59 + 1911643955 * x ^ 58 + 1713852330 * x ^ 57 + 1757273231 * x ^ 56 + 1778819295 * x ^ 55 + 957146826 * x ^ 54 + 900005615 * x ^ 53 + 521467961 * x ^ 52 + 1255707235 * x ^ 51 + 861871574 * x ^ 50 + 397953653 * x ^ 49 + 1259753202 * x ^ 48 + 471431762 * x ^ 47 + 1245956917 * x ^ 46 + 1688297180 * x ^ 45 + 1536178591 * x ^ 44 + 1833258462 * x ^ 43 + 1369087493 * x ^ 42 + 459426544 * x ^ 41 + 418389643 * x ^ 40 + 1800239647 * x ^ 39 + 2467433889 * x ^ 38 + 477713059 * x ^ 37 + 1898813986 * x ^ 36 + 2202042708 * x ^ 35 + 894088738 * x ^ 34 + 1204601190 * x ^ 33 + 1592921228 * x ^ 32 + 2234027582 * x ^ 31 + 1308900201 * x ^ 30 + 461430959 * x ^ 29 + 718926726 * x ^ 28 + 2081988029 * x ^ 27 + 1337342428 * x ^ 26 + 2039153142 * x ^ 25 + 1364177470 * x ^ 24 + 613659517 * x ^ 23 + 853968854 * x ^ 22 + 1013582418 * x ^ 21 + 1167857934 * x ^ 20 + 2014147362 * x ^ 19 + 1083466865 * x ^ 18 + 1091690302 * x ^ 17 + 302196939 * x ^ 16 + 1946675573 * x ^ 15 + 2450124113 * x ^ 14 + 1199066291 * x ^ 13 + 401889502 * x ^ 12 + 712045611 * x ^ 11 + 1850096904 * x ^ 10 + 1808400208 * x ^ 9 + 1567687877 * x ^ 8 + 2013445952 * x ^ 7 + 2435360770 * x ^ 6 + 2414019676 * x ^ 5 + 2277377050 * x ^ 4 + 2148341337 * x ^ 3 + 1073721716 * x ^ 2 + 1045363399 * x + 1809685811
 
c = 922927962 * x ^ 254 + 1141958714 * x ^ 253 + 295409606 * x ^ 252 + 1197491798 * x ^ 251 + 2463440866 * x ^ 250 + 1671460946 * x ^ 249 + 967543123 * x ^ 248 + 119796323 * x ^ 247 + 1172760592 * x ^ 246 + 770640267 * x ^ 245 + 1093816376 * x ^ 244 + 196379610 * x ^ 243 + 2205270506 * x ^ 242 + 459693142 * x ^ 241 + 829093322 * x ^ 240 + 816440689 * x ^ 239 + 648546871 * x ^ 238 + 1533372161 * x ^ 237 + 1349964227 * x ^ 236 + 2132166634 * x ^ 235 + 403690250 * x ^ 234 + 835793319 * x ^ 233 + 2056945807 * x ^ 232 + 480459588 * x ^ 231 + 1401028924 * x ^ 230 + 2231055325 * x ^ 229 + 1716893325 * x ^ 228 + 16299164 * x ^ 227 + 1125072063 * x ^ 226 + 1903340994 * x ^ 225 + 1372971897 * x ^ 224 + 242927971 * x ^ 223 + 711296789 * x ^ 222 + 535407256 * x ^ 221 + 976773179 * x ^ 220 + 533569974 * x ^ 219 + 501041034 * x ^ 218 + 326232105 * x ^ 217 + 2248775507 * x ^ 216 + 1010397596 * x ^ 215 + 1641864795 * x ^ 214 + 1365178317 * x ^ 213 + 1038477612 * x ^ 212 + 2201213637 * x ^ 211 + 760847531 * x ^ 210 + 2072085932 * x ^ 209 + 168159257 * x ^ 208 + 70202009 * x ^ 207 + 1193933930 * x ^ 206 + 1559162272 * x ^ 205 + 1380642174 * x ^ 204 + 1296625644 * x ^ 203 + 1338288152 * x ^ 202 + 843839510 * x ^ 201 + 460174838 * x ^ 200 + 660412151 * x ^ 199 + 716865491 * x ^ 198 + 772161222 * x ^ 197 + 924177515 * x ^ 196 + 1372790342 * x ^ 195 + 320044037 * x ^ 194 + 117027412 * x ^ 193 + 814803809 * x ^ 192 + 1175035545 * x ^ 191 + 244769161 * x ^ 190 + 2116927976 * x ^ 189 + 617780431 * x ^ 188 + 342577832 * x ^ 187 + 356586691 * x ^ 186 + 695795444 * x ^ 185 + 281750528 * x ^ 184 + 133432552 * x ^ 183 + 741747447 * x ^ 182 + 2138036298 * x ^ 181 + 524386605 * x ^ 180 + 1231287380 * x ^ 179 + 1246706891 * x ^ 178 + 69277523 * x ^ 177 + 2124927225 * x ^ 176 + 2334697345 * x ^ 175 + 1769733543 * x ^ 174 + 2248037872 * x ^ 173 + 1899902290 * x ^ 172 + 409421149 * x ^ 171 + 1223261878 * x ^ 170 + 666594221 * x ^ 169 + 1795456341 * x ^ 168 + 406003299 * x ^ 167 + 992699270 * x ^ 166 + 2201384104 * x ^ 165 + 907692883 * x ^ 164 + 1667882231 * x ^ 163 + 1414341647 * x ^ 162 + 1592159752 * x ^ 161 + 28054099 * x ^ 160 + 2184618098 * x ^ 159 + 2047102725 * x ^ 158 + 103202495 * x ^ 157 + 1803852525 * x ^ 156 + 446464179 * x ^ 155 + 909116906 * x ^ 154 + 1541693644 * x ^ 153 + 166545130 * x ^ 152 + 2283548843 * x ^ 151 + 2348768005 * x ^ 150 + 71682607 * x ^ 149 + 484339546 * x ^ 148 + 669511666 * x ^ 147 + 2110974006 * x ^ 146 + 1634563992 * x ^ 145 + 1810433926 * x ^ 144 + 2388805064 * x ^ 143 + 1200258695 * x ^ 142 + 1555191384 * x ^ 141 + 363842947 * x ^ 140 + 1105757887 * x ^ 139 + 402111289 * x ^ 138 + 361094351 * x ^ 137 + 1788238752 * x ^ 136 + 2017677334 * x ^ 135 + 1506224550 * x ^ 134 + 648916609 * x ^ 133 + 2008973424 * x ^ 132 + 2452922307 * x ^ 131 + 1446527028 * x ^ 130 + 29659632 * x ^ 129 + 627390142 * x ^ 128 + 1695661760 * x ^ 127 + 734686497 * x ^ 126 + 227059690 * x ^ 125 + 1219692361 * x ^ 124 + 635166359 * x ^ 123 + 428703291 * x ^ 122 + 2334823064 * x ^ 121 + 204888978 * x ^ 120 + 1694957361 * x ^ 119 + 94211180 * x ^ 118 + 2207723563 * x ^ 117 + 872340606 * x ^ 116 + 46197669 * x ^ 115 + 710312088 * x ^ 114 + 305132032 * x ^ 113 + 1621042631 * x ^ 112 + 2023404084 * x ^ 111 + 2169254305 * x ^ 110 + 463525650 * x ^ 109 + 2349964255 * x ^ 108 + 626689949 * x ^ 107 + 2072533779 * x ^ 106 + 177264308 * x ^ 105 + 153948342 * x ^ 104 + 1992646054 * x ^ 103 + 2379817214 * x ^ 102 + 1396334187 * x ^ 101 + 2254165812 * x ^ 100 + 1300455472 * x ^ 99 + 2396842759 * x ^ 98 + 2398953180 * x ^ 97 + 88249450 * x ^ 96 + 1726340322 * x ^ 95 + 2004986735 * x ^ 94 + 2446249940 * x ^ 93 + 520126803 * x ^ 92 + 821544954 * x ^ 91 + 1177737015 * x ^ 90 + 676286546 * x ^ 89 + 1519043368 * x ^ 88 + 224894464 * x ^ 87 + 1742023262 * x ^ 86 + 142627164 * x ^ 85 + 1427710141 * x ^ 84 + 1504189919 * x ^ 83 + 688315682 * x ^ 82 + 1397842239 * x ^ 81 + 435187331 * x ^ 80 + 433176780 * x ^ 79 + 454834357 * x ^ 78 + 1046713282 * x ^ 77 + 1208458516 * x ^ 76 + 811240741 * x ^ 75 + 151611952 * x ^ 74 + 164192249 * x ^ 73 + 353336244 * x ^ 72 + 1779538914 * x ^ 71 + 1489144873 * x ^ 70 + 213140082 * x ^ 69 + 1874778522 * x ^ 68 + 908618863 * x ^ 67 + 1058334731 * x ^ 66 + 1706255211 * x ^ 65 + 708134837 * x ^ 64 + 1382118347 * x ^ 63 + 2111915733 * x ^ 62 + 1273497300 * x ^ 61 + 368639880 * x ^ 60 + 1652005004 * x ^ 59 + 1977610754 * x ^ 58 + 1412680185 * x ^ 57 + 2312775720 * x ^ 56 + 59793381 * x ^ 55 + 1345145822 * x ^ 54 + 627534850 * x ^ 53 + 2159477761 * x ^ 52 + 10450988 * x ^ 51 + 1479007796 * x ^ 50 + 2082579205 * x ^ 49 + 1158447154 * x ^ 48 + 126359830 * x ^ 47 + 393411272 * x ^ 46 + 2343384236 * x ^ 45 + 2191577465 * x ^ 44 + 1281188680 * x ^ 43 + 230049708 * x ^ 42 + 539600199 * x ^ 41 + 1711135601 * x ^ 40 + 1659775448 * x ^ 39 + 1716176055 * x ^ 38 + 904363231 * x ^ 37 + 2385749710 * x ^ 36 + 567278351 * x ^ 35 + 404199078 * x ^ 34 + 372670353 * x ^ 33 + 1286079784 * x ^ 32 + 1744355671 * x ^ 31 + 2316856064 * x ^ 30 + 2106475476 * x ^ 29 + 614988454 * x ^ 28 + 2149964943 * x ^ 27 + 1065233185 * x ^ 26 + 188130174 * x ^ 25 + 540415659 * x ^ 24 + 1031409799 * x ^ 23 + 1067085678 * x ^ 22 + 1005161755 * x ^ 21 + 249654085 * x ^ 20 + 1816791634 * x ^ 19 + 1437500292 * x ^ 18 + 448596413 * x ^ 17 + 2397497659 * x ^ 16 + 2353732701 * x ^ 15 + 2068949189 * x ^ 14 + 1826419168 * x ^ 13 + 1265366199 * x ^ 12 + 547031306 * x ^ 11 + 1016962374 * x ^ 10 + 160089486 * x ^ 9 + 2264803979 * x ^ 8 + 1081806194 * x ^ 7 + 824215340 * x ^ 6 + 497731793 * x ^ 5 + 45017166 * x ^ 4 + 317548920 * x ^ 3 + 1391127733 * x ^ 2 + 1752881284 * x + 1290424106
S.<x> = R.quotient(N)  # 关于x的瑞利定理
 
P, Q = N.factor()
P, Q = P[0], Q[0]
phi = (p ** P.degree() - 1) * (p ** Q.degree() - 1)
e = 0x10001
d = invert(e, phi)
 
m = pow(c, d, N)
m = "".join([chr(c) for c in m.list()])
print(m)
#flag{h4v3_y0u_533n_p0lyn0m14l_b453d_r54??}

6.HZNUCTF2023初赛——child_OTP:异或运算

flag = 'HZNUCTF{****************}'.strip('HZNUCTF{').strip('}')
mask = 'It_is_My_Mask!!!'
cipher = ''.join([chr(ord(flag[i]) ^ ord(mask[i])) for i in range(len(flag))])
print(cipher.encode())
b'#\x01j^,\x1f#&lyT\n4Y\x11S'

分析题目:

  • flag = ‘HZNUCTF{************}’.strip(‘HZNUCTF{’).strip(‘}’),从字符串中删除前缀’HZNUCTF{'和后缀,只留下星号。

  • cipher = ‘’.join([chr(ord(flag[i]) ^ ord(mask[i])) for i in range(len(flag))])

    这一行迭代字符串中的每个字符,和flag中相应字符的 ASCII 值之间执行 XOR 运算。将结果转换回字符,然后将所得字符连接在一起形成字符串。

解题:

  • 进行逆运算
  • 将flag与cipher的位置互换
  • 用decode()反过来解码cipher

代码如下:

mask = 'It_is_My_Mask!!!'
cipher=(b'#\x01j^,\x1f#&lyT\n4Y\x11S').decode()
flag = ''.join([chr(ord(cipher[i]) ^ ord(mask[i])) for i in range(len(cipher))])
print("HZNUCTF{"+flag+"}")

7.HZNUCTF2023初赛——child_quadratic_residue

from Crypto.Util.number import *
flag = b"HZNUCTF{*********************************************}".strip(b'HZNUCTF{').strip(b'}')
flag = bytes_to_long(flag)
p = getPrime(1024)
while p % 4 != 3:
    p = getPrime(1024)
assert flag ** 2 % p == 205840081872741614533018920392769203485102161354394579376850093717710932843926743420261035196159236788699786704721272784083171485301715527552338861282446970643372396898033472140600377881068935045649635754249798345769
print(p)
#92514668543122735752371270312562927033333784558218172827882746297130751282337768353244176170371267417126292468877685711835064518828362290725503081237676172797761025897668830938846775719804590062950271155237320408576251153507336919751071518361423760807270332690021771143981485402084845399742269025273998595431

分析题目:

  • 根据题目名字,搜索了解到了quadratic residue——二次剩余定理,简要来讲就是d在模p的情况下,会不会是某个数的平方,会则为二次剩余。
  • 接下来看题目内容,令c=flag ** 2 % p
  • 既然用了二次剩余,可以大胆地猜一下c=flag**2,所以用iroot()开根计算一下:
from Crypto.Util.number import *
import gmpy2
p=92514668543122735752371270312562927033333784558218172827882746297130751282337768353244176170371267417126292468877685711835064518828362290725503081237676172797761025897668830938846775719804590062950271155237320408576251153507336919751071518361423760807270332690021771143981485402084845399742269025273998595431
c=205840081872741614533018920392769203485102161354394579376850093717710932843926743420261035196159236788699786704721272784083171485301715527552338861282446970643372396898033472140600377881068935045649635754249798345769
flag=gmpy2.iroot(c,2)[0]
print(long_to_bytes(flag))
#b"1t_74k35_s0me_me@sures_wh3n_r3m41nd3r_15n'7_3"

解出来了,直接出答案。

8.HZNUCTF2023初赛——child_proof_work

from uuid import *
from hashlib import md5

flag = 'HZNUCTF{' + str(uuid4()) + '}'

assert md5(flag.encode()).hexdigest() == 'b49780de39c67aa53fdba5615e0216bf'
assert flag[:-6] == 'HZNUCTF{75920709-9c50-4337-90c9-0893f9b'

分析题目:

  • 首先看题的内容:flag用了md5加密,并且flag的开头到倒数第六位之前,是已知的,所以可以尝试爆破遍历列表,虽然道理明白,但代码我还不会写,只能看学姐的……正好再涨涨知识:
from uuid import *
from hashlib import md5
import itertools
c = 'HZNUCTF{75920709-9c50-4337-90c9-0893f9b'
combinations = list(itertools.product('0123456789abcdef', repeat=5))
b = []
for combination in combinations:
    b.extend(list(''.join(combination) for i in combination))
for i in b:
    flag = c + ''.join(i) + '}'
    if md5(flag.encode()).hexdigest() == 'b49780de39c67aa53fdba5615e0216bf':
        print(flag)
        break
#HZNUCTF{75920709-9c50-4337-90c9-0893f9b094e0}
  • 首先导入了itertools模块来生成字符组合。
  • 接着生成了一个列表,使用itertools.product()从’0123456789abcdef’生成五个字符的所有可能组合,并将它们存储在combinations列表中。
  • 初始化一个空列表b来存储扩展组合。
  • 迭代每种组合combinations并将它们连接在一起以形成长度为 5 的字符串。然后将这些字符串添加到b列表中。
  • 检查计算出的哈希值是否与目标哈希值匹配
    a53fdba5615e0216bf’:
    print(flag)
    break
    #HZNUCTF{75920709-9c50-4337-90c9-0893f9b094e0}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值