ellipticcurve

ECDSA

#EllipticCurve ベースポイント (位数) 秘密鍵 公開鍵 署名 のx座標とする で が署名 検証 , とする なので、この のx座標が と等しいことを確認する r, sからP=dGを求める は のx座標なので を復元して とすると

singular curve

#EllipticCurve 特異点(Singular Point)を持つ楕円曲線のこと。特異点の様子によってNode型かCusp型かに分けられる。 SingularなEllipticCurveは同型な別の群への写像を持ち、離散対数問題が簡単になることがある CuspかNodeか調べる 特異点(のx座標)を調…

Crypto CTF 2021 | Rohald

#cryptoctf2021 #!/usr/bin/env sage from Crypto.Util.number import * from secret import flag, Curve def ison(C, P): c, d, p = C u, v = P return (u**2 + v**2 - c**2 * (1 + d * u**2*v**2)) % p == 0 def teal(C, P, Q): c, d, p = C u1, v1 = P u2…

CSAW CTF Qualification Round 2019 | Supercurve

#ECDH #ECDLP """ supercurve.py An implementation of a weak elliptic curve over a prime field in standard Weirstrauss form: y^2 = x^3 + ax + b Derived from: https://github.com/andreacorbellini/ecc/blob/master/logs/common.py """ class SuperC…

zer0pts CTF 2022 | CurveCrypto

#zer0ptsCTF2022 import os from random import randrange from Crypto.Util.number import bytes_to_long, long_to_bytes, getStrongPrime from Crypto.Util.Padding import pad from fastecdsa.curve import Curve def xgcd(a, b): x0, y0, x1, y1 = 1, 0,…

Union CTF | Mordell Primes

#UnionCTF from Crypto.Util.number import bytes_to_long from secrets import k, FLAG assert k < 2^128 assert FLAG.startswith(b'union{') E = EllipticCurve(QQ,[0,1,0,78,-16]) P = E(1,8) Q = k*P R = (k+1)*P p = Q[0].numerator() q = R[0].numerat…

HITCON CTF 2022 | Chimera

#HITCON_CTF_2022 import os from Crypto.Util.number import bytes_to_long, getPrime from Crypto.Cipher import AES from Crypto.Util.Padding import pad from hashlib import sha256 from secret import flag p = getPrime(384) q = getPrime(384) n = …

BSides Ahmedabad CTF 2021 | ECC-RSA2

#bsidesahmedabadctf_2021 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)…

Crypto CTF 2021 | Ecchimera

#cryptoctf2021 #!/usr/bin/env python3 from sage.all import * from flag import flag n = 43216667049953267964807040003094883441902922285265979216983383601881964164181 U = 1823029494546684219302946481817610962847341445869345527252784978012143…

CYBER APOCALYPSE CTF 2021 | Super Metroid

#cyber_apocalypse_ctf_2021 from Crypto.Util.number import bytes_to_long, getPrime from secrets import FLAG def gen_key(): from secrets import a,b E1 = EllipticCurve(F, [a,b]) assert E.is_isomorphic(E1) key = - F(1728) * F(4*a)^3 / F(E1.dis…

SECCON 2021 | XXX

#seccon2021 import os flag = os.getenv("FLAG", "fake{fakeflag_blahblah}") x = int.from_bytes(flag.encode(), "big") p = random_prime(1 << int(x.bit_length() * 2.5)) Fp = GF(p) params = [] while len(params) != 6: try: y = randint(2, x) a = r…

Ledger Donjon CTF 2021 | Brittle Little Secret

https://ctftime.org/writeup/31972 #BLS12-381 #EllipticCurve

Google CTF 2021 | H1

#googlectf2021 #!/usr/bin/python3 import os import hashlib from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import padding from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, m…

justCTF 2020 | 25519

#justCTF_2020 #!/use/bin/env sage from sys import exit from hashlib import sha256 FLAG = open('./flag.txt').read() ec = EllipticCurve(GF(2**255-19), [0, 486662, 0, 1, 0]) p = ec.order() ZmodP = Zmod(p) G = ec.lift_x(9) ha = lambda x: x if …

anomalous curve

EllipticCurveにおいて、であるようなもの、flobenious traceが1であるような曲線。このような曲線に対しては、SSSAAttackやSmart Attackによって、離散対数問題が多項式時間で解ける 楕円曲線の位数がであるとき、そのようなをanomalous primeといい、また…

RaR CTF 2021 | psychecc

#rarctf2021 from collections import namedtuple import random def moddiv(x,y,p): return (x * pow(y, -1, p)) %p Point = namedtuple("Point","x y") class EllipticCurve: INF = Point(0,0) def __init__(self, a, b, p): self.a = a self.b = b self.p…

Crytpo CTF 2021 | Elegant Curve

#cryptoctf2021 #!/usr/bin/env python3 from Crypto.Util.number import * import sys from flag import flag def tonelli_shanks(n, p): if pow(n, int((p-1)//2), p) == 1: s = 1 q = int((p-1)//2) while True: if q % 2 == 0: q = q // 2 s += 1 else: …

UIUCTF 2020 | nook crypt

EllipticCurve option 1では との結果を得ることができる。ただし時折 が壊れた値になるらしい option 2では 任意の平文 に対してを計算してもらえる まずは楕円曲線上の点を集めて楕円曲線のパラメータを当てるところからやる。 に対して 同様に この2式に…

N1CTF 2020 | curve

#!/usr/bin/env sage import signal, hashlib, string, random, os os.chdir(os.path.dirname(os.path.abspath(__file__))) FLAG = open("./flag.txt", 'r').read() ROUNDS = 30 def PoW(): s = ''.join([random.choice(string.ascii_letters + string.digit…

Crypto CTF 2021 | Double Miff

#cryptoctf2021 #!/usr/bin/env python3 from Crypto.Util.number import * from secret import a, b, p, P, Q from flag import flag def onmiff(a, b, p, G): x, y = G return (a*x*(y**2 - 1) - b*y*(x**2 - 1)) % p == 0 def addmiff(X, Y): x_1, y_1 = …

ペアリング

Weil Pairing tate pairing EllipticCurveを用いた鍵共有方式 楕円曲線上の2点の組から、ある有限体への写像のこと 性質 (ただし

nullcon HackIM 2019|Singular

#nullconHackIM2019 https://ctftime.org/task/7528 https://gitlab.com/n0tsobad/ctf-writeups/tree/master/2019-02-01-nullcon/Singular https://grosquildu.github.io/writeups/2019/01/03/nullcon-singular/ https://crypto.stackexchange.com/questions…

BSides Noida CTF | low power crypto

#bsidesnoidactf from Crypto.Util.number import getRandomNBitInteger, isPrime # extended gcd def egcd(a, b): old_x, new_x = 1, 0 old_y, new_y = 0, 1 while a != 0: q, a, b = b // a, b % a, a new_x, old_x = old_x, new_x - q * old_x new_y, old…

ASIS CTF 2020 | Elliptic Curve

EllipticCurve 楕円曲線上に点 が存在することを教えられ、その三点のうち、ある一点 を渡されるので、を計算して送る ここでは、を貰ったと仮定する y^2 = (x+2)^3 + a(x + 2) + b (mod p) = x^3 + 6x^2 + 12x + 8 + ax + 2a + b (mod p) y^2 = (x+1)^3 + a…

watevr ctf 2019 | ECC-RSA

#EllipticCurve from fastecdsa.curve import P521 as Curve from fastecdsa.point import Point from Crypto.Util.number import bytes_to_long, isPrime from os import urandom from random import getrandbits def gen_rsa_primes(G): urand = bytes_to_…

ASIS CTF Quals 2019 | Halloween Party

#ASISCTFQuals2019 https://ctftime.org/task/8320 In the halloween party, we want to half a delicious but small cake! flag = ASIS{P.x} #!/usr/bin/env python from fastecdsa.curve import Curve from fastecdsa.point import Point from Crypto.Util…

ACSC 2021 | swap on curve

#acsc2021 from params import p, a, b, flag, y x = int.from_bytes(flag, "big") assert 0 < x < p assert 0 < y < p assert x != y EC = EllipticCurve(GF(p), [a, b]) assert EC(x,y) assert EC(y,x) print("p = {}".format(p)) print("a = {}".format(a…

ECDH

楕円曲線ディフィー・ヘルマン鍵共有のこと。EllipticCurveを用いて第三者に知られないように鍵を共有する。 公開パラメータとして E: とそのベースポイントGを用意しておく それぞれがランダムな値a, b を決める aG, bGを公開鍵として交換する 3 abG を共有…

CPCTF 2023 | misuse

#cpctf_2023 """This code is designed to be run with SageMath. See https://www.sagemath.org/ If you don't have SageMath installed, you can use the online version at https://cocalc.com/ or https://sagecell.sagemath.org/ But you may not use p…

N1CTF | flagbot

from hashlib import sha256 from Crypto.Cipher import AES from Crypto.Util.number import long_to_bytes, bytes_to_long from Crypto.Util.Padding import pad, unpad import base64 from secret import flag RECEIVER_NUM = 7 def generate_safecurve()…