Skip to content

Instantly share code, notes, and snippets.

@kanav99
Created November 6, 2021 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanav99/954d04b8a188f5b1eb6fde13d33b33cc to your computer and use it in GitHub Desktop.
Save kanav99/954d04b8a188f5b1eb6fde13d33b33cc to your computer and use it in GitHub Desktop.
from Crypto.Util.number import getPrime
from hashlib import sha256
import random
def gen_parameters():
p = getPrime(512)
q = getPrime(512)
N = p * q
a = -3
while True:
b = random.randint(0, N)
if (4*a**3 + 27*b**2) % N != 0:
break
x = random.randint(0, N)
while True:
y2 = (x**3 + a*x + b) % N
if Zmod(p)(y2).is_square() and Zmod(q)(y2).is_square():
break
x = random.randint(0, N)
y = CRT([int(Zmod(p)(y2).sqrt()), int(Zmod(q)(y2).sqrt())], [p, q])
return (N, a, b, (x, y))
with open("flag.txt", "rb") as f:
FLAG = f.read().strip()
N, a, b, (x, y) = gen_parameters()
EC = EllipticCurve(Zmod(N), (a, b))
P = EC(x, y)
T = P
ct = []
for byte in FLAG:
r = int(T.xy()[0])
ct.append(pow(byte*r, 65537, N))
T += T
with open("backdoor.txt", "w") as f:
f.write(str(P.xy()))
print(N)
print(a)
print(b)
print(ct)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment