Skip to content

Instantly share code, notes, and snippets.

@y011d4
y011d4 / solve_zmod.sage
Created July 18, 2023 06:55
zer0pts CTF 2023 Elliptic Ring RSA solver
import re
p = 211
q = 192
a = 201
b = 102
e = 13
Fp = GF(p)
Zq = Zmod(q)
E = EllipticCurve(Fp, [a, b])
@y011d4
y011d4 / solve.sage
Created May 18, 2023 13:09
my solver for DDLP in HackTM 2023 Finals
primes = list(prime_range(1000000))
# 4p = 1 + Dy^2, p = p1 * p2 * ... * pm + 1
# 4 * p1 * ... * pm + 3 = D * y^2 (p1 should be 2)
# 8 * p2 * ... * pm = D * y^2 - 3 = (sqrt(D) * y - sqrt(3)) * (sqrt(D) * y + sqrt(3))
# when D = 27, r.h.s. = 3 * (3*y - 1) * (3*y + 1)
cnt = 0
y3_min = int(sqrt(2 ** 255 * 4 // 3))
y3_max = int(sqrt(2 ** 256 * 4 // 3))
while True:
@y011d4
y011d4 / solve.py
Created November 9, 2022 01:46
N1CTF brand_new_checkin
import random
from Crypto.Util.number import bytes_to_long, long_to_bytes
from z3 import *
N = 624
M = 397
MATRIX_A = 0x9908B0DF
UPPER_MASK = 0x80000000
@y011d4
y011d4 / solve.sage
Last active May 22, 2022 13:12
my solver for zer0lfsr++ in 0CTF/TCTF 2021
import random
from z3 import *
from tqdm import tqdm
from functools import lru_cache
from collections import Counter
from itertools import combinations
import time
def _prod(L):
# https://static.chunichi.co.jp/chunichi/pages/feature/QR/galois_field_in_auto_factory.html
X = GF(2).polynomial_ring().gen()
poly = X ** 8 + X ** 4 + X ** 3 + X ** 2 + 1
F = GF(2 ** 8, name="a", modulus=poly)
R.<x> = PolynomialRing(F)
def tobin(x, n):
x = Integer(x)
nbits = x.nbits()
@y011d4
y011d4 / angstrom_caniride.py
Created May 5, 2022 03:24
solver for caniride in angstromCTF 2022
from pwn import *
elf = ELF("./caniride")
context.binary = elf
REMOTE = True
if REMOTE:
io = remote("challs.actf.co", 31228)
libc = ELF("./libc.so.6")
@y011d4
y011d4 / simple_csidh.sage
Last active December 26, 2023 12:17
simple CSIDH implementation. DO NOT use for cryptographic purpose.
# Use a small prime for brevity
p = 4 * 3 * 5 * 7 - 1
primes = [3, 5, 7]
Fp = GF(p)
def from_weierstrass(EC):
a, b = EC.a4(), EC.a6()
F = EC.base_field()
PR = PolynomialRing(F, name="z")
@y011d4
y011d4 / solve_smart_cryptooo.py
Last active September 17, 2021 03:44
solver for smart_cryptooo chall in defcon quals
import binascii
import itertools
import struct
import numpy as np
import torch
import torch.nn as nn
# configurable stuff
bits = 64