fib = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] enc = '10000100100 10010000010 10010001010 10000100100 10010010010 10001000000 10100000000 10000100010 00101010000 10010010000 00101001010 10000101000 10000010010 00101010000 10010000000 10000101000 10000010010 10001000000 00101000100 10000100010 10010000100 00010101010 00101000100 00101000100 00101001010 10000101000 10100000100 00000100100' enc = enc.split(' ') flag = '' for i in enc: n = 0 for j inrange(len(fib)): if i[j] == '1': n += fib[len(fib)-j-1] flag += chr(n) print(flag)
corctf{b4s3d_4nd_f1bp!113d}
Crypto-4096
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from Crypto.Util.number import getPrime, bytes_to_long from private import flag
defprod(lst): ret = 1 for num in lst: ret *= num return ret
m = bytes_to_long(flag) primes = [getPrime(32) for _ inrange(128)] n = prod(primes) e = 65537 print(n) print(pow(m, e, n))
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env sage # -*- coding: utf-8 -*- from Crypto.Util.number import long_to_bytes from gmpy2 import invert n = 50630448182626893495464810670525602771527685838257974610483435332349728792396826591558947027657819590790590829841808151825744184405725893984330719835572507419517069974612006826542638447886105625739026433810851259760829112944769101557865474935245672310638931107468523492780934936765177674292815155262435831801499197874311121773797041186075024766460977392150443756520782067581277504082923534736776769428755807994035936082391356053079235986552374148782993815118221184577434597115748782910244569004818550079464590913826457003648367784164127206743005342001738754989548942975587267990706541155643222851974488533666334645686774107285018775831028090338485586011974337654011592698463713316522811656340001557779270632991105803230612916547576906583473846558419296181503108603192226769399675726201078322763163049259981181392937623116600712403297821389573627700886912737873588300406211047759637045071918185425658854059386338495534747471846997768166929630988406668430381834420429162324755162023168406793544828390933856260762963763336528787421503582319435368755435181752783296341241853932276334886271511786779019664786845658323166852266264286516275919963650402345264649287569303300048733672208950281055894539145902913252578285197293 c = 15640629897212089539145769625632189125456455778939633021487666539864477884226491831177051620671080345905237001384943044362508550274499601386018436774667054082051013986880044122234840762034425906802733285008515019104201964058459074727958015931524254616901569333808897189148422139163755426336008738228206905929505993240834181441728434782721945966055987934053102520300610949003828413057299830995512963516437591775582556040505553674525293788223483574494286570201177694289787659662521910225641898762643794474678297891552856073420478752076393386273627970575228665003851968484998550564390747988844710818619836079384152470450659391941581654509659766292902961171668168368723759124230712832393447719252348647172524453163783833358048230752476923663730556409340711188698221222770394308685941050292404627088273158846156984693358388590950279445736394513497524120008211955634017212917792675498853686681402944487402749561864649175474956913910853930952329280207751998559039169086898605565528308806524495500398924972480453453358088625940892246551961178561037313833306804342494449584581485895266308393917067830433039476096285467849735814999851855709235986958845331235439845410800486470278105793922000390078444089105955677711315740050638 e = 0x10001 phi = 1 for i in factor(n): phi *= i[0]-1 print(long_to_bytes(pow(c, invert(e, phi), n)))
from pwn import xor from Crypto.Util.number import long_to_bytes from binascii import unhexlify p = 20936670545375210972091706288423179494163425035286134775773514440843943493090886819895346572945288304582498268271507942037581752184819846906869395551921930704321251130746547888224652316226957634541702883599286787839982090615950687496752999645558331533314682453610929822041558882012483238149288762974740347582024050756443700107245858419316423473568526347559377124536218894368962796664914408327949348396038507355935608178392088898784474582354438590711083089253977971653913217304360725716982473871023235180637867588860233011122300656470435644430602412710493441965130162664981423496370539240693045312454250776393871037539 q = 19872523115298089612152987731023453644084277408261276810219001288407280019889227914287760742936580023163800626696116882213533508813201232707621762739857924392306902336092739272758773377952936022982446120177174082641600741522817135305633293579042208014735900229922142564590095968054337719254632703676737069746032384348392244892496672044899073391936273280270753785076044108870166304800552404013519058026991588856235381264192387525832530187004466616791531223421070547342377071358044704265893255021275811622959301157507095984825182110574434699593886509171425701861331576642311553357835312334349976576969220483604368671153 r = 18342695102288954165224207958150786487860883752676419020596228714991017967256173183699487408637445601341687447489432163178271335469203559084363600703497940503946684342504933131623546315643648637992201226732630680112575643707020017139390225257319697353426087369722671485915571962910153169877358046375850132351117527591675467417925944135644417622440847857598273517926844822766083086147088819776687612745404553608100705862181700054385028096749375873889019995159762301115707945396140178370414857973922007665218670792403129624089144668480280115489465764431016721028424152163659378120333071194425845370101841510224643446231 c = b'6255a505b969be8175a5c578fd6e856ecd85faa1a22fdf38d2d11851211676fd3047ed12c4027e66ed2173495877180e3d49a387b74701fbbbdce00a2248c7812b157626c95e7cf5727ee90cc9a6a98d84ee50f106b11245d65b87a27bbd7ab94b0d82eeb6e49e81249ae880c150ff87d8da701e9d317932fa2b27b64eb894a112d942d7d269478a6c120be885f3fbd065c38e70498c2f294b47bb08da09fb63c05070248079fe4311c9821dd8d3a08b15f13cdb0b7a8d406790c4796e0218851b496a11bf1ad7575be6d9999d5f1c73080d724c66a116f865ffcd3048be5d59dae55a4a063629d30429765733521702ec36d3f111b015934d15d620ad0e35ee56' print(xor(unhexlify(c), long_to_bytes(2*q)))
n = 73542616560647877565544036788738025202939381425158737721544398356851787401183516163221837013929559568993844046804187977705376289108065126883603562904941748653607836358267359664041064708762154474786168204628181667371305788303624396903323216279110685399145476916585122917284319282272004045859138239853037072761 e = 0x10001 flag = bytes_to_long(open("flag.txt", "rb").read())
n = 73542616560647877565544036788738025202939381425158737721544398356851787401183516163221837013929559568993844046804187977705376289108065126883603562904941748653607836358267359664041064708762154474786168204628181667371305788303624396903323216279110685399145476916585122917284319282272004045859138239853037072761 e = 65537 ct = 2657054880167593054409755786316190176139048369036893368834913798649283717358246457720021168590230987384201961744917278479195838455294205306264398417522071058105245210332964380113841646083317786151272874874267948107036095666198197073147087762030842808562672646078089825632314457231611278451324232095496184838
Transcription of image:735426165606478775655440367887380252029393814251587377215443983568517874011835161632289108065126883603562904941748653607836358267359664041064708762154474786168204628181914547691658512291728431928227200404585913823985303707276110829444070104535359586724271966052237452625064069019356304826385480674852517237933134107826924653229965686488122367909872459351442286770449287037546500722564119233842472664209076816421439063259825039563231146143146482074105407
from Crypto.Cipher import AES from Crypto.Util import Counter from Crypto.Util.Padding import pad, unpad from Crypto.Util.number import bytes_to_long import os
flag = open("/challenge/flag.txt").read().encode() key = os.urandom(16)
defencrypt(pt): iv = os.urandom(16) ctr = Counter.new(128, initial_value=bytes_to_long(iv)) cipher = AES.new(key, AES.MODE_CTR, counter=ctr) return iv + cipher.encrypt(pad(pt, 16))
from random import randrange from Crypto.Util.number import getPrime, long_to_bytes from Crypto.Cipher import AES from Crypto.Util.Padding import pad from hashlib import sha256 from os import urandom
flag = open("flag.txt", "rb").read()
defund(): p = getPrime(512) x = randrange(p) a = p ^ x ^ randrange(2**200) b = p ^ x ^ randrange(2**200) return p, a, b, x
print('now, i want you to sign my message.') r = int(input('give me r>')) s = int(input('give me s>')) if verify(r, s, mymsg): print("nice. i'll give you the flag.") print(flag) else: print("no, that's wrong.")
想要verify成功,获得flag
1 2 3 4 5
defverify(r, s, m): v1 = H(m)*inverse(s, N) % N v2 = r*inverse(s, N) % N V = v1*G + v2*pub returnint(V.x) % N == r
for _ inrange(4): m = bytes.fromhex(input('give me something to sign, in hex>')) h = H(m) if m == mymsg or h in signed_hashes: print("i won't sign that.") exit() signed_hashes.append(h) r, s = sign(m) print('r:', str(r)) print('s:', str(s))
看下具体签名的过程
1 2 3 4 5
defsign(m): k = next(gen) r = int((k*G).x) % N s = ((H(m) + d*r)*inverse(k, N)) % N return r, s
$$ r=kx\ mod\ n $$ $$ s=(m+rd)\cdot k^{-1}\ mod\ n $$
#!/usr/bin/env sage # -*- coding: utf-8 -*- # nc crypto.be.ax 6002 from Crypto.Util.number import bytes_to_long, inverse from hashlib import sha256 from gmpy2 import * from fastecdsa.curve import P256 from pwn import *
# context.log_level = 'debug' sh = remote('crypto.be.ax', 6002) G = P256.G N = P256.q
defH(m): h = sha256() h.update(m) return bytes_to_long(h.digest())
defegcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y
defmodinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m
defcrack_unknown_increment(states, m, a): b = (states[1] - states[0] * a) % m return m, a, b
defcrack_unknown_multiplier(states, m): a = (states[2] - states[1]) * modinv(states[1] - states[0], m) % m return crack_unknown_increment(states, m, a)
# LCG part sequence = [] for m inrange(4): inv = invert(G.x, N) sh.recvuntil(b'give me something to sign, in hex>') sh.sendline(str(m).encode().hex()) sh.recvuntil(b'r:') r = int(sh.recvline().decode()) sh.recvuntil(b's:') s = int(sh.recvline().decode()) k = (int(r) * int(inv)) % N d = ((int(s) * k - H(str(m).encode())) * int(invert(int(r), N))) % N print('d =', d) # d = 111794286037145166785531145837405642417111081891011940999958121590200481323527 # d = 32439466539999346636384702841656953540974828530354787685779441994658571451022 # d = 10926244771926014704519302388552973799549625394927395188718476150973064437377 # d = 114762443346016561170498759027815574796335775581660017547791545655526389133816
English: Our best agent is going to send us a message from an enemy country. But instead, he just posted some stupid player on his page! Find his public key immediately and send us the first 42 symbols in an appropriate form so we can be sure it’s him. For example, YAUZActf{Tgj8t6gbK9zlv4Xmivyhttjzvfbbp7nuqkce3uuomF}