def cmd_order(args): """append curve order to the file, oops""" with open(args.file) as f: lines = f.readlines() i = 0 with open(args.file + '.orders', 'w') as f: for line in lines: i += 1 print(f'{i:04d}', end='\r') line = line.strip() a, b, p, P = eval(line) E = EllipticCurve(GF(p), (a, b)) Po = E(P).order() o = E.order() f.write(repr((a, b, p, o, P, Po)) + '\n')
def do_offline() -> None: print('{"command":"sign", "params":{"command":"info"}}') p = int(input('p: ')) a = int(input('a: ')) b = int(input('b: ')) Hxy = eval(input('H: ')) Gxy = eval(input('G: ')) E = EllipticCurve(GF(p), [a, b]) H = E(Hxy) G = E(Gxy) key = pohlig(E, H, G) print(f'solved: {key}') # now we forge a signed request with the 'flag' command print('forging request...') request = make_request('flag', name='fbctf') message = json.dumps(request, sort_keys=True) R, S = sign(message, key, E.order(), G) sig = base64.b64encode(bytes(str(R) + '|' + str(S), 'utf-')) request['sig'] = sig.decode('utf-8') print(json.dumps(request, sort_keys=True))
from time import time from point_counting.naive import naive_order def measure_time(func, *args): t = time() res = func(*args) print(f"Function took {time()-t} seconds to run") return res # print(time("challenge", "challenges.exceptional_curves", "")) # a,b,p = 46, 74, 97 a, b, p = (1333, 1129, 3571) E = EllipticCurve(GF(p), [a, b]) print(E.order()) F = FiniteField(p) E2 = EC(F, a, b) print(measure_time(naive_order, E2)) print(measure_time(schoof, E2)) """ E = EllipticCurve(GF(p), [a, b]) print(E.order()) F = FiniteField(p) E2 = EC(F, a, b) print(measure_time(schoof, E2)) """ """ ec_test_values = [ (13, 215, 229), (106, 166, 197), (31, 16, 137), (503, 367, 523),
info = do_request(store, make_signed(store, 'info')) print(info) curve_s, gen_s, pub_s = info.split('\n') _, ax, bmp = curve_s.split('+') a = int(ax.split('*')[0]) b = int(bmp.split('(')[0]) p = int(bmp.split('mod')[1][:-1]) Gxy = eval(gen_s.split(': ')[1]) assert isinstance(Gxy, tuple) and len(Gxy) == 2 Hxy = eval(pub_s.split(': ')[1]) assert isinstance(Hxy, tuple) and len(Hxy) == 2 print(f'a: {a}\nb: {b}\np: {p}\ngen: {Gxy}\npub: {Hxy}') # done parsing curve, now use pohlig to get a priv key print(f'doing pohlig...') E = EllipticCurve(GF(p), [a, b]) H = E(Hxy) G = E(Gxy) key = pohlig(E, H, G) print(f'solved: {key}') # now we forge a signed request with the 'flag' command print('forging request...') request = make_request('flag', name='fbctf') message = json.dumps(request, sort_keys=True) R, S = sign(message, key, E.order(), G) sig = base64.b64encode(bytes(str(R) + '|' + str(S), 'utf-')) request['sig'] = sig.decode('utf-8') r = do_request(store, request) print(r) # FLAG!