from secret import FLAG, ECDH_KEY_EXCHANGE from Crypto.Cipher import AES from hashlib import md5
import binascii
iv = urandom(16)
a = 14489 b = 10289 p = 7486573182795736771889604737751889118967735916352298289975055815020934891723453392369540853603360270847848895677903334441530052977221688450741083448029661
from hashlib import sha384, sha256 from Crypto.Util.number import inverse from secret import k,privkey,flag defsign(msg, privkey,k,order): e = int(sha384(msg).hexdigest(), 16) K = k*G r = int(K[0]) k_ = inverse(k, order) s = k_ * (e + privkey * r) % order return r, s
q = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff a = -3 b = 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef M = 8368031831458217786350512159882992957012870179737136526893923006288695827959478962195704930743648877201823593529339381563729143350454126812624495126388843 x = 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7 y = 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f E = EllipticCurve(GF(q), [0,0,0,a, b]) G = E([x,y]) msg1=b'hello' r1,s1=sign(msg1,privkey,k,q) print("r1 =",r1) print("s1 =",s1) k2=(a*k+b) % M msg2=b'world' r2,s2=sign(msg2,privkey,k2,q) print("r2 =",r2) print("s2 =",s2) key = sha256(str(privkey).encode()).digest() aes = AES.new(key, AES.MODE_ECB) ct = base64.b64encode(aes.encrypt(pad(flag, 16))).decode()
from sympy.ntheory.residue_ntheory import nthroot_mod from Crypto.Util.number import * from Crypto.Cipher import AES from random import randrange,choice from hashlib import * from secret import flag
import socketserver import os import signal import string
table = string.ascii_letters+string.digits
nbit = 128
defpad(m,lenth): return m + bytes([i for i inrange(lenth-int(len(m)%lenth))])
classTask(socketserver.BaseRequestHandler): def_recvall(self): BUFF_SIZE = 2048 data = b'' whileTrue: part = self.request.recv(BUFF_SIZE) data += part iflen(part) < BUFF_SIZE: break return data.strip()
for _ inrange(len(b'vnctf2023') - 8): self.send(b"Send 2 `y' elements to me: ") ans = self.recv() try: y1, y2 = [int(_) % q for _ in ans.split(b',')] except: self.send(b"Your parameters are not valid! Bye!!") break
#sage from pwn import * from itertools import product import string from hashlib import sha256 from random import getrandbits from ast import literal_eval from Crypto.Util.number import * from Crypto.Cipher import AES
table = string.ascii_letters+string.digits
defset_connect_proof(): io=remote('node4.buuoj.cn','25385') io.recvuntil(b"sha256(XXXX+") alphabet = string.ascii_letters + string.digits lattar_part=io.recv(16).decode('utf8') io.recvuntil(b'== ') h=io.recvline().strip().decode('utf8') # print(h) io.recvuntil(b'[+] Plz Tell Me XXXX :') bruteforce=[ ''.join(prefix)+lattar_part for prefix in product(alphabet,repeat=4)] for proof in bruteforce: if sha256(proof.encode()).hexdigest()==h: io.sendline(proof.encode()[:4]) print("proof done") return io
whileTrue: io = set_connect_proof() io.recvuntil(b"Send 2 `y' elements to me: ") y1,y2 = getrandbits(128),getrandbits(128) io.sendline(f'{str(y1)},{str(y2)}'.encode()) q = int(io.recvline_contains(b'q = ').decode().strip()[4:]) G = literal_eval(io.recvline_contains(b"G = ").decode().strip()[4:]) mG = literal_eval(io.recvline_contains(b"m * G = ").decode().strip()[8:]) encflag = io.recvline_contains(b'encrypt flag = ').decode().strip()[len(b'encrypt flag = '):] AA = (y1**2 - y2**2 - 2022**3 + 2023**3) * inverse(-1, q) % q BB = (y1**2 - 2022**3 - AA * 2022) % q E = EllipticCurve(GF(q), [AA, BB]) g_order = E(G).order() order_ls = factor(g_order) print(f"[+] G order {order_ls}") sub_group_order = 1 for p,e in order_ls: if p.nbits() <= 42: sub_group_order*= (p^e) expon = g_order//sub_group_order print(f"[+] {sub_group_order.nbits() = }") if sub_group_order.nbits() < 120: io.close() continue mm = discrete_log(expon*E(mG),expon*E(G),ord = sub_group_order,operation = "+") print(f"[+] subgroup dlp (m mod {sub_group_order}) = ", mm) io.close() break
aes = AES.new(int(mm).to_bytes(16, 'big'), AES.MODE_CBC, bytes(16)) flag = aes.decrypt(bytes.fromhex(encflag)) print(flag)
t = GF(p)(193387944202565886198256260591909756040).square_root() u = (P_[1] + t*P_[0])/(P_[1] - t*P_[0]) % p v = (Q_[1] + t*Q_[0])/(Q_[1] - t*Q_[0]) % p print (v.log(u))