CTF Crypto --- 随缘做题

crypto1

题目:

XOR-π
3.1415926535897932384626433832795028841971


85 66 80 83 74 1 13 2 15 81 5 83 89 20 85 10 5 3 30 9 3 85 86 27 87 4 4 91 85 86 26 13 83 86 86 0 1 5 80 92 85 76

根据题目意思直接和π异或即可

#!python3
# -*- coding: utf-8 -*-
# @Time    : 2023/6/21 15:01
# @Author  : 3tefanie丶zhou

key = '3.1415926535897932384626433832795028841971'
enc = '85 66 80 83 74 1 13 2 15 81 5 83 89 20 85 10 5 3 30 9 3 85 86 27 87 4 4 91 85 86 26 13 83 86 86 0 1 5 80 92 85 76'.split(" ")
flag = ''
for i in range(len(enc)):
    flag +=chr(int(enc[i])^ord(key[i]))
print(flag)

flag:

flag{4409d6fa-b361-17cd-c77cfd-4ffd891aeb}

crypto2

题目:

托尼获取到了一个宝藏,让老师鉴定了下

宝藏鉴定结果:
9f39f51068b088b8


但托尼又不小心损坏了宝藏:
synt{0643qq1*-*63p-57n*-*584o6-0*74o0q25o}

先利用泄露的部分md5值爆破密文,最后rot13一下即可得到flag

import itertools
from  hashlib import md5
import string
dict = string.printable[:36]

for i in itertools.product(dict,repeat=5):
    key = "synt{{0643qq1{0}-{1}63p-57n{2}-{3}584o6-{4}s74o0q25o}}".format(i[0], i[1], i[2], i[3],i[4])
    hash_value = md5(key.encode('utf-8')).hexdigest()
    if '9f39f51068b088b8' in hash_value:
        flag = ''
        for i in key:
            if i.islower():
                flag += chr(ord(i) - 13)
            else:
                flag += i
        print(flag)
        break

flag:

flag{0643dd10-863c-57a7-c584b6-0f74b0d25b}

crypto3

题目:

from Crypto.Util.number import *
flag = ***********
m=bytes_to_long(flag)
p = getPrime(1024)
q = getPrime(1024)
e = ***********
e1 = 2023
n = p*q
h1=pow((p+q),e1,n)
h2=pow((p-q),e1,n)
c=pow(m,e,n)
print(n)
print(h1)
print(h2)
print(c)

30183656394805107357196370521008780218925570049861387216169054600381560517999947182495011076202126709273160644370262874124968897163730207965220921744326193258358200657778320099962189812662073746049174190737733696870138306766952659451198803418491107784028230018858597385184003464461324726173514428396625540948387202029576333925489299994380848535683878295861054849479745468667103738387433149825519903102622708548565692424513329009043335422465827135431803716962258640474502935517125459339414944346181909028036411407296618452373689029356418425024260765592536962977787010290927682883045452686496078325690903591609011622649
7931354967841361677225525366492283823894590697656669456900404637225452955459348179528014507555386203547449783236442156583903338871101372231379416298673332475841552351685699019468753684327399291889812282583934998862651749254999550865157778659585029993856246293740166651157267243002539956928571725540194386430135556941941158115392325448899508409029275561616503138231793202722531305888967930689408754797831414396346372778070017194895510733987493231643773783381517911590791997520439013140032231243105419628779624880308940011265642047838378068375393042924607140918207395722101771037631402904373527746525020704973321077960
25062305644512626278872554723682407404832559793666087363222623557675770421081399157255725073992481546436446297869801169592204892169276487493822396167281356628851048304904314012479222859204326040757182928968731733798383263988650657055905914856184098798472993044182269108543644164055399204428716761331393401597324716686296821274763372210790827746803211415514983448406120655928961667116170309904869353511506605306453153870397660846835063923643054746025854226394115291053816754538318359343733736423501470671478388599730283824290134464908259553611786880318768864343694812103186674192588648465811660170572517267553070038503
10566050200491898237861779349951184912833923661795629392708549602522205458471596364817182905986707189288385851923975592583132325630526948547284585859263336194822093938912144662726671172596366107238257782270698285219710310820716655379358362338786357841955558739297544011078781470192343051678062312416475601556385198608232848554523600840313604027144055153075238544724194720089578983488275239449599014873939408460792984830861989839765653149206345119917698514546823183643061389802526139765069463102068988065342441036929752116505115330236182894409200589686944842338651901005676000551266948519276949174935413951432934098553

h1和h2二项式展开分别得到
h 1 = p e 1 + q e 1   m o d   n h_1 = p^{e_1}+q^{e_1} \space mod \space n h1=pe1+qe1 mod n
h 2 = p e 1 − q e 1   m o d   n h_2 = p^{e_1}-q^{e_1} \space mod \space n h2=pe1qe1 mod n
h 1 + h 2 = 2 ∗ p e 1   m o d   n h_1+h_2 = 2*p^{e_1} \space mod \space n h1+h2=2pe1 mod n
显然与n存在最大公约数p,直接gcd即可求得p
然后爆破一下e2即可

from Crypto.Util.number import *
import gmpy2

n = 30183656394805107357196370521008780218925570049861387216169054600381560517999947182495011076202126709273160644370262874124968897163730207965220921744326193258358200657778320099962189812662073746049174190737733696870138306766952659451198803418491107784028230018858597385184003464461324726173514428396625540948387202029576333925489299994380848535683878295861054849479745468667103738387433149825519903102622708548565692424513329009043335422465827135431803716962258640474502935517125459339414944346181909028036411407296618452373689029356418425024260765592536962977787010290927682883045452686496078325690903591609011622649
h1 = 7931354967841361677225525366492283823894590697656669456900404637225452955459348179528014507555386203547449783236442156583903338871101372231379416298673332475841552351685699019468753684327399291889812282583934998862651749254999550865157778659585029993856246293740166651157267243002539956928571725540194386430135556941941158115392325448899508409029275561616503138231793202722531305888967930689408754797831414396346372778070017194895510733987493231643773783381517911590791997520439013140032231243105419628779624880308940011265642047838378068375393042924607140918207395722101771037631402904373527746525020704973321077960
h2 = 25062305644512626278872554723682407404832559793666087363222623557675770421081399157255725073992481546436446297869801169592204892169276487493822396167281356628851048304904314012479222859204326040757182928968731733798383263988650657055905914856184098798472993044182269108543644164055399204428716761331393401597324716686296821274763372210790827746803211415514983448406120655928961667116170309904869353511506605306453153870397660846835063923643054746025854226394115291053816754538318359343733736423501470671478388599730283824290134464908259553611786880318768864343694812103186674192588648465811660170572517267553070038503
c = 10566050200491898237861779349951184912833923661795629392708549602522205458471596364817182905986707189288385851923975592583132325630526948547284585859263336194822093938912144662726671172596366107238257782270698285219710310820716655379358362338786357841955558739297544011078781470192343051678062312416475601556385198608232848554523600840313604027144055153075238544724194720089578983488275239449599014873939408460792984830861989839765653149206345119917698514546823183643061389802526139765069463102068988065342441036929752116505115330236182894409200589686944842338651901005676000551266948519276949174935413951432934098553
p = gmpy2.gcd(h1+h2,n)
q = n//p
phi = (p-1)*(q-1)
for e in range(1,100000000):
    try:
        d = gmpy2.invert(e, phi)
        m = pow(c,d,n)
        flag = long_to_bytes(m)
        if b'flag' in flag:
            print(f'e = {e}')
            print(flag)
            break
    except:
        pass

flag:

flag{97065396-788c-5274-d5e0d9-ce1c33af3c}

crypto4

题目:

from Crypto.Util.number import *
from gmpy2 import *
from random import *

flag = b'flag{xxxxxxxxxxxxxxx}'
m = bytes_to_long(flag)
p = getPrime(1024)
q = getPrime(1024)
n = p * q
e1 = randint(1, 65538)
e2 = 9647291
assert gcd(e1, e2) == 1

c1 = pow(m, e1, n)
c2 = pow(m, e2, n)

a = randint(n // 2, n)
b = randint(n // 2, n)
x = randint(n // 2, n)
hint1 = (a * c1 + 1023 * x) % n
hint2 = (b * c1 + 1024 * x) % n
hint3 = c2 * n


print('n =', n)
print("a =", a)
print("b =", b)
print("hint1 =", hint1)
print("hint2 =", hint2)
print("hint3 =", hint3)
# n = 16125407552864408038451978971181995868587415471360339980312161114604643561448189461178314426572196867330062460236485889607095216773610462673103525772850249723607127265156082437903554965291175082962639383670937777311212896542972880424526079735786844389686957083365598937203322023931600269428448046149266341128554306213612397973685363189571686506630309830089220474201802073858959449101463678487317186076440791650250365012789827421324921778250883488990582944368562892797416344251060566529139850257746842799863322714616986446835293581697909698285176760388107157669554377276259762618665488257388491160075176338147719827037
# a = 13322099359978468117372945784425510444699489610016328757147661948295406516253823721585011191447575070678806499049706999293540250271665120018677590850034030368730195727460200565297326051740643004879691301619699301106930837198015487978219038035197723076156409255613823021037443587984496717728543374662454371480847535762439189824812004916125039891869564141181736162482872749048932562058201189900746478873842107591299649081305019213582364534953875369121945643746097376620917802772688252466567153568522092062992030417712736678853318751806058050273319844033309624611135341470435429322414596904369077559157148448414839032363
# b = 10275112473052097822163214291710245927601932098450526023436146936515575568966157279003404407528918111137316033319928861357294023493650299285411997308906967017629349471597059845459569991332848036825641333607579647087347485564553165670865364947248868251173085509024531668592291055640081009491476771331141299698791088908862211221687025549332282038419404819610705192095183951267650322294156121830068680857085069554177406709624092077033969271498007410828074096659664006111360389535517799171965089132885207983699725930677229877112464611768708080016125996142926911506613455696889598916644316886658721740850065556243938007810
# hint1 = 5646585199324712910174870876537963922935541552960135665854448183261083672983331653471842641925332927782315514511532766879190801929980994592200158530247219526312018092215417868738295218479822713259089033062819804918266548266840411490391265219709570414166619339434539050638762944531192598576491596621743816843125895668542438923918478344982739955475060988594676093550481119457143084943131533380243144975602778461714997734422024740849870491507544447233405634629786945527801001275734833662623467945946282795996306293408310273736674209426457392716416888243874745568105752845915237400340094943662551705685040442624941385833
# hint2 = 14585520416190000580445268935877639341764643969476248446269709488912338827970488844346831212422329420900792189527752187774994153342996351962929221182898317644166070626979324794061661833397604017568609862262727324814815424928736663001245135821828306087205636823484794573005890510152188674905462762148100329985991698959636488617249906898501964648111982813010371107696317126789702686935854736324220969771123819040020121221332632913284083499130218851636149172445983987305390603339306926120007456352189098000654123268951023801063278397184055390984864816637614344524008267690049801207931569396692120561972519603849989128993
# hint3 = 62093942844955894809744369157790919272709918861758380679821577778048849347738275395666159786314235217854818169109692941511405178089534902688354311428283671061156522101189015915319595816373429513381246644721630263218045931797340921607548704947248385584064891710829013112219974267785184786002337877737639709838592212626216662132226423917011307673560256826430488539866716857680736031883178590790995624532262186067634107387809349232152735759985335934241188954392212538014367792568155050961352578224455757803682195904635225691590570030418963654743371040135500179324783700281415394891744127799547005015135086532660545095391079521112740890332419993624820181300060863161311031709022851421455500566323115875683812425673042153124072114571960643827025713430499560735327945430769108097870643289355930786864376038045754477540741831426313486186208377194724677735876320331562117490978784291302590568890413248378029250309728695855535870140308467228980587481032478718831718081368010375598581706830265936563271354286383793280590954702836704366205681837777194310753890918642427863999918174783991318434802104950572826848043286819209577713010622615357988184856985035869968426847979577245836140860190327001050885833097619703928776547085778778592553120373

已知a,b,n,hint1,hint2,hint3
显然是一个共模攻击,那么我们就需要知道c1c2e1e2n
易知, c 2 = h i n t 3 n c_2 =\frac{hint_3}{n} c2=nhint3
主要是求c1
我们联立hint1hint2消除x
1024 ∗ h i n t 1 = 1024 ∗ a ∗ c 1 + 1023 ∗ 1024 ∗ x   m o d   n 1024*hint_1 = 1024*a*c_1+1023*1024*x \space mod \space n 1024hint1=1024ac1+10231024x mod n
1023 ∗ h i n t 2 = 1023 ∗ b ∗ c 1 + 1023 ∗ 1024 ∗ x   m o d   n 1023*hint_2 = 1023*b*c_1+1023*1024*x \space mod \space n 1023hint2=1023bc1+10231024x mod n
两式相减
1024 ∗ h i n t 1 − 1023 ∗ h i n t 2 = ( 1024 ∗ a − 1024 ∗ b ) ∗ c 1   m o d   n 1024*hint_1-1023*hint_2 = (1024*a-1024*b)*c_1 \space mod \space n 1024hint11023hint2=(1024a1024b)c1 mod n
⇒ c 1 = ( 1024 ∗ h i n t 1 − 1023 ∗ h i n t 2 ) ∗ ( 1024 ∗ a − 1024 ∗ b ) − 1   m o d   n \Rightarrow c_1 = (1024*hint_1-1023*hint_2)*(1024*a-1024*b)^{-1} \space mod \space n c1=(1024hint11023hint2)(1024a1024b)1 mod n
之后爆破一下e1,共模攻击一下即可得到flag

from Crypto.Util.number import *
import gmpy2


n = 16125407552864408038451978971181995868587415471360339980312161114604643561448189461178314426572196867330062460236485889607095216773610462673103525772850249723607127265156082437903554965291175082962639383670937777311212896542972880424526079735786844389686957083365598937203322023931600269428448046149266341128554306213612397973685363189571686506630309830089220474201802073858959449101463678487317186076440791650250365012789827421324921778250883488990582944368562892797416344251060566529139850257746842799863322714616986446835293581697909698285176760388107157669554377276259762618665488257388491160075176338147719827037
a = 13322099359978468117372945784425510444699489610016328757147661948295406516253823721585011191447575070678806499049706999293540250271665120018677590850034030368730195727460200565297326051740643004879691301619699301106930837198015487978219038035197723076156409255613823021037443587984496717728543374662454371480847535762439189824812004916125039891869564141181736162482872749048932562058201189900746478873842107591299649081305019213582364534953875369121945643746097376620917802772688252466567153568522092062992030417712736678853318751806058050273319844033309624611135341470435429322414596904369077559157148448414839032363
b = 10275112473052097822163214291710245927601932098450526023436146936515575568966157279003404407528918111137316033319928861357294023493650299285411997308906967017629349471597059845459569991332848036825641333607579647087347485564553165670865364947248868251173085509024531668592291055640081009491476771331141299698791088908862211221687025549332282038419404819610705192095183951267650322294156121830068680857085069554177406709624092077033969271498007410828074096659664006111360389535517799171965089132885207983699725930677229877112464611768708080016125996142926911506613455696889598916644316886658721740850065556243938007810
hint1 = 5646585199324712910174870876537963922935541552960135665854448183261083672983331653471842641925332927782315514511532766879190801929980994592200158530247219526312018092215417868738295218479822713259089033062819804918266548266840411490391265219709570414166619339434539050638762944531192598576491596621743816843125895668542438923918478344982739955475060988594676093550481119457143084943131533380243144975602778461714997734422024740849870491507544447233405634629786945527801001275734833662623467945946282795996306293408310273736674209426457392716416888243874745568105752845915237400340094943662551705685040442624941385833
hint2 = 14585520416190000580445268935877639341764643969476248446269709488912338827970488844346831212422329420900792189527752187774994153342996351962929221182898317644166070626979324794061661833397604017568609862262727324814815424928736663001245135821828306087205636823484794573005890510152188674905462762148100329985991698959636488617249906898501964648111982813010371107696317126789702686935854736324220969771123819040020121221332632913284083499130218851636149172445983987305390603339306926120007456352189098000654123268951023801063278397184055390984864816637614344524008267690049801207931569396692120561972519603849989128993
hint3 = 62093942844955894809744369157790919272709918861758380679821577778048849347738275395666159786314235217854818169109692941511405178089534902688354311428283671061156522101189015915319595816373429513381246644721630263218045931797340921607548704947248385584064891710829013112219974267785184786002337877737639709838592212626216662132226423917011307673560256826430488539866716857680736031883178590790995624532262186067634107387809349232152735759985335934241188954392212538014367792568155050961352578224455757803682195904635225691590570030418963654743371040135500179324783700281415394891744127799547005015135086532660545095391079521112740890332419993624820181300060863161311031709022851421455500566323115875683812425673042153124072114571960643827025713430499560735327945430769108097870643289355930786864376038045754477540741831426313486186208377194724677735876320331562117490978784291302590568890413248378029250309728695855535870140308467228980587481032478718831718081368010375598581706830265936563271354286383793280590954702836704366205681837777194310753890918642427863999918174783991318434802104950572826848043286819209577713010622615357988184856985035869968426847979577245836140860190327001050885833097619703928776547085778778592553120373
e2 = 9647291
c2 = hint3//n
c1 = ((1024*hint1-1023*hint2)*gmpy2.invert(1024*a-1023*b,n)) % n
for e1 in range(1,65539):
    if gmpy2.gcd(e1,e2)==1:
        g,s1,s2 = gmpy2.gcdext(e1,e2)
        m = pow(c1,s1,n)*pow(c2,s2,n)%n
        flag = long_to_bytes(m)
        if b'flag' in flag:
            print(f'e1 = {e1}')
            print(flag)
            break
    else:
        pass

flag:

flag{cb53fffb-d184-b0ae-32d709-2412143b48}

【心地是福田,言行是风水,只有懂的惜福,才能藏风聚水。】

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值