from sage.allimport * from libnum import n2s n = 14381700422128582509148801752355744589949207890477326887251636389639477554903212313766087310581920423926674144511237847467160303159477932732842314969782540035709454603184976310835433114879043016737665256729350745769071186849072915716081380191025215059636548339167264601163525017898164466972776553148697204889820118261937316228241099344357088387154112255824092894798716597134811437852876763391697588672779069166285303075312833415574850549277205130215394422655325352478386576833373623679069271857652029364332047485797407322257853316210866532938722911480593571175419708834718860211036796987231227104370259051299799633809 c1 = 7213976567554002619445032200800186986758840297933991288547009708561953107405266725278346810536664670987171549114913443730366439254199110599202411546254632702440251000149674899033994570393935743323319736976929843596350656674709510612789987746895513057821629144725499933366382123251520676386059405796801097683107223771674383940907066300331503757142088898427893069444164604408189686282018392714450005250018004986102062209998463347007934222341910941474212611569508001910685822097788669516018081617394144015000387497289693096617795809933540456797387940627782045397249431573540932386564021712811633992948508497879189416719996092292320828635490820907122756459412206735413770335545012892724496210585503157766011075566023635046144730429791359690237088629187946232458937292767085665897489251315749496284368726255508362410603108788759785472319449267909859926786774679533591222665476101832482161295321411313525830843915966136814748249906589458905410141906965538387896747375546846618213595165688661941876715858338407833641907024891922856719044736945863722003318526031957256722493189062624177017279248142024760515092698242159769372410662895078523142768353100643884341413944795392762315999109544070401451087596138520908569234305384182336436670714204963907240715652950621301644972412252424876159530992 m1 = ((c1 - 1)//(n**2)) * inverse_mod(233,n) m1 = m1%n print(n2s(int(m1%n))) #b'flag{11e89e28-4e27-47'
1 2 3 4 5 6 7 8
from sage.allimport * D = 1117 c = continued_fraction(sqrt(D)) for i inrange(10000): x,y = c.numerator(i),c.denominator(i) if x**2 - D * y**2 == 1: x0,y0 = x,y break
import os import ecdsa import hashlib from Crypto.Util.number import * from Crypto.Util.strxor import strxor as xor import secret
p = getPrime(256) gen = lambda: p + getPrime(16) pad = lambda m: m + os.urandom(32 - len(m) % 32)
key = os.urandom(30) sk = ecdsa.SigningKey.from_secret_exponent( secexp=bytes_to_long(key), curve=ecdsa.SECP256k1 ) sig1 = sk.sign(data=b'This is the first message.', k=gen()).hex() sig2 = sk.sign(data=b'Here is another message.', k=gen()).hex() enc = xor(hashlib.sha512(key).digest(), pad(secret.flag)).hex()
from ecdsa.util import sigdecode_string from ecdsa import SECP256k1 from hashlib import sha1,sha512 from Crypto.Util.strxor import strxor as xor from sage.allimport inverse_mod from ecdsa._compat import normalise_bytes from ecdsa.keys import _truncate_and_convert_digest sig1 = '3f4a6f288e35a4397201d246a98c1f9cfa463e67717fbbdcbd26d7fac75f875855455c2bfb355f7f593ffbe4c4bd1fc729cc129976b56905639100c8ac716b37' sig2 = '9f563b21f0ee31b2f7a1a8c6edc8ff23b63e0a9d5dd4a699ecc3164871b4982df51bb2feb4bc06c578afd21d3e6227231dd5fe1d8440f3dcd025fd3ea68f5516' enc = 'cc66d251bfa54954890c81dc1c607bae716573949f327db18aa1f4c0f420b8d29dc7e7ff9edb17b90306bd2aa753fc3fd4dafb9cc4b771cbdd79000ef05a40c0' enc = bytes.fromhex(enc) r1,s1 = sigdecode_string(bytes.fromhex(sig1),int(SECP256k1.order)) r2,s2 = sigdecode_string(bytes.fromhex(sig2),int(SECP256k1.order)) p = int(SECP256k1.curve.p()) # hashfunc使用的是sha1 h1 = int(sha1(b'This is the first message.').hexdigest(),16) h2 = int(sha1(b'Here is another message.').hexdigest(),16) n = int(SECP256k1.order)
for kr inrange(-(1<<16),1<<16): kr %= n key = (s1*s2*kr - h1*s2 + h2*s1)*inverse_mod(r1*s2-r2*s1,n) % n try: key = bytes.fromhex(hex(int(key))[2:].zfill(60)) res = (xor(sha512(key).digest(), enc)) ifb'flag'in res: print(res) except: continue #b'flag{2f64731e-785b-4259-4566-3d17554bfb7b}\xed\x98\x98\xbc\x92+\xc7\x7f\xe2_\xfd\x17\x1e\x9c\xf7\x17Rq\xfa3\xa2{'
#!/usr/bin/env sage # Problem by rec, with nothing. import secret import os import random from Crypto.Cipher import AES from Crypto.Util.Padding import pad from sage.allimport *
t = 17 ps = PolynomialRing(Zmod(p),[var('p%02d'%i) for i inrange(t+1)]).gens() # ps = [var('p%02d'%i) for i in range(t+1)] poly = [0for i inrange(601)] for i inrange(len(pos)): poly[pos[i]] = ps[i] Q = list(Q) for i inrange(len(Q)): Q[i] = int(Q[i])
from tqdm import tqdm
defdivmod(a:list[int],b:list[int],p): # an,bn记录多项式的长度 # 默认a,b的系数都小于p an,bn = len(a)-1,len(b)-1 assert an>bn or (an == bn and a[an] > b[bn]), "被除数过小" for i in tqdm(range(an,bn-1,-1)):
if a[i] == 0: continue tmp = p - a[i] # print(tmp) tmp_b = [b[i]*tmp for i inrange(bn+1)] # print(tmp_b) for j inrange(bn,-1,-1): a[i-bn+j] += tmp_b[j]
return a res = divmod(poly,Q,p)
for i inrange(len(res)): if'p'instr(res[i]): continue res[i] = int(res[i]) % p fangcheng = [0for i inrange(430)] for i inrange(430): fangcheng[i] = res[i] - int(list(hint)[i]) juzhen = [[0for j inrange(18)] for i inrange(429)] www = [0for i inrange(429)] for equa inrange(429): tmp = list(fangcheng[equa]) for i inrange(len(tmp)): iflen(str(tmp[i][1])) > 1: juzhen[equa][int(str(tmp[i][1])[1:])] = tmp[i][0] else: www[equa] = tmp[i][0] A = Matrix(Zmod(p),juzhen) enc = bytes.fromhex(enc)
最后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from Crypto.Cipher import AES
for x in (A.solve_right(vector(Zmod(p),www))): print((int(x) % int(p))-p) key = bytes.fromhex(hex(275609957223526193497841020687316070508)[2:]) print(len(key)) print(key)
use actix_files::NamedFile; use actix_web::{App, HttpRequest, HttpResponse, HttpServer, Responder, Result, web, get, post, guard}; use std::path::PathBuf;