#!/usr/bin/env python3 from Crypto.Util.number import * import random import os import hashlib
FLAG = os.getenv("FLAG", "PCTF{flag}").encode("utf8") FLAG = bytes_to_long(FLAG[5:-1]) assert FLAG.bit_length() < 384
BITS = 1024
defxor(a, b): returnbytes([i ^ j for i, j inzip(a, b)])
# This doesn't really matter right??? defcustom_hash(n): state = b"\x00" * 16 for i inrange(len(n) // 16): state = xor(state, n[i : i + 16])
for _ inrange(5): state = hashlib.md5(state).digest() state = hashlib.sha1(state).digest() state = hashlib.sha256(state).digest() state = hashlib.sha512(state).digest() + hashlib.sha256(state).digest()
value = bytes_to_long(state)
return value
deffiat_shamir(): p = getPrime(BITS) g = 2 y = pow(g, FLAG, p)
v = random.randint(2, 2**512)
t = pow(g, v, p) c = custom_hash(long_to_bytes(g) + long_to_bytes(y) + long_to_bytes(t)) r = (v - c * FLAG) % (p - 1)
# https://github.com/chainlight-io/publications/blob/main/ctf-writeups/paradigm2023/oven from pwn import * from Crypto.Util.number import * from tqdm import trange
defparse(): t = get_arg('t') r = get_arg('r') p = get_arg('p') g = get_arg('g') y = get_arg('y')
return t, r, p, g, y
defcustom_hash(n): state = b"\x00" * 16 for i inrange(len(n) // 16): state = xor(state, n[i : i + 16])
for _ inrange(5): state = hashlib.md5(state).digest() state = hashlib.sha1(state).digest() state = hashlib.sha256(state).digest() state = hashlib.sha512(state).digest() + hashlib.sha256(state).digest()
value = bytes_to_long(state)
return value
arr = []
for _ in trange(20): conn.sendlineafter(b'Choice: ', b'1') t, r, p, g, y = parse()
c = custom_hash(long_to_bytes(g) + long_to_bytes(y) + long_to_bytes(t))
arr.append((c, r, p))
mat = []
mat.append([ -it[0] for it in arr ] + [1, 0])
for i inrange(20): row = [0] * i + [ arr[i][2] - 1 ] + [0] * (20 - i) + [0] mat.append(row)
mat.append([ -it[1] for it in arr ] + [0, 2^512])
mat = Matrix(mat)
res = mat.LLL()
for row in res: t = int(row[-2]) if t < 0: t = -t print(long_to_bytes(t))