import random from hashlib import sha256 from Crypto.Cipher import AES from Crypto.Util.Padding import pad from Crypto.Util.number import * from Curve import curve
FLAG = b"flag{????????????????????????????}"
defpoint_add(P, Q): x3 = (P[0] * Q[0] + D * P[1] * Q[1]) % p y3 = (P[0] * Q[1] + P[1] * Q[0]) % p return (x3, y3)
defscalar_multiplication(P, n): Q = (1, 0) while n > 0: if n % 2 == 1: Q = point_add(Q, P) P = point_add(P, P) n = n // 2 return Q
# D = 841 # G = (70210196346326018298323228783367869223089211897379057380061203281233621280100334, 101948468141045147243060203936353465018134737325641287102428542544766828444719731) # A = (72026969273392981774418076966986362461956111553551088611979083382924817005972811, 128201817310525593386581249545813413509552341431389561637102898055038847720854727) # B = (118405884118567563062281530746539956049083561398150145014305536274191594242083518, 190549637299382268483032246904983195711360085884080305886613955302147251245442613) # C = a6e0d676c05ea6a75f7a4d3b73a8646df745f62adbec1d957693bc8077e59d4aeca100c5fe118cfa1c1fba4f105f2787
from hashlib import sha256 from Crypto.Cipher import AES from Crypto.Util.Padding import pad,unpad from Crypto.Util.number import * from gmpy2 import *
defpoint_add(P, Q): x3 = (P[0] * Q[0] + D * P[1] * Q[1]) % p y3 = (P[0] * Q[1] + P[1] * Q[0]) % p return (x3, y3)
defscalar_multiplication(P, n): Q = (1, 0) while n > 0: if n % 2 == 1: Q = point_add(Q, P) P = point_add(P, P) n = n // 2 return Q
D = 841 G = (70210196346326018298323228783367869223089211897379057380061203281233621280100334, 101948468141045147243060203936353465018134737325641287102428542544766828444719731) A = (72026969273392981774418076966986362461956111553551088611979083382924817005972811, 128201817310525593386581249545813413509552341431389561637102898055038847720854727) B = (118405884118567563062281530746539956049083561398150145014305536274191594242083518, 190549637299382268483032246904983195711360085884080305886613955302147251245442613)
# 计算素数 p p = gcd((A[0] ** 2 - D * A[1] ** 2) - 1, (B[0] ** 2 - D * B[1] ** 2) - 1)
# decrypt flag C = "a6e0d676c05ea6a75f7a4d3b73a8646df745f62adbec1d957693bc8077e59d4aeca100c5fe118cfa1c1fba4f105f2787" c = bytes.fromhex(C) key = sha256(long_to_bytes(shared_secret)).digest() cipher = AES.new(key, AES.MODE_ECB) flag = cipher.decrypt(c) print(unpad(flag,16))