Skip to content

Instantly share code, notes, and snippets.

@theoremoon
theoremoon / schoof.sage
Last active January 2, 2023 14:09
Schoofのアルゴリズムによって楕円曲線の位数を求めるやつ - in yoshicamp 2022
from functools import cache
def division_polynomial(E, n, x=None):
if x is None:
PR = PolynomialRing(E.base())
x = PR.gen()
a, b = E.a4(), E.a6()
F = 4*(x**3 + a*x + b)
@theoremoon
theoremoon / aes-gcm.sage
Created March 27, 2022 05:52
AES-GCMを多項式で愚直に表すとわかりやすいね
from Crypto.Cipher import AES
import secrets
F = GF(2**128, name="a", modulus=x**128 + x**7 + x**2 + x + 1)
def to_poly(x):
bs = Integer(int.from_bytes(x, "big")).bits()[::-1]
return F([0] * (128 - len(bs)) + bs)
def qtest(xs):
m = len(xs)
ts = [sum(x) for x in xs]
tbar = sum(ts) / m
ss = []
for i in range(len(xs[0])):
s = 0
for j in range(len(xs)):
s += xs[j][i]

avast/retdec をcloneしてきてビルドした後、retdec::deps::eigen が見つからないといってretdecを用いたプログラムのコンパイルに失敗した時の対処

import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
std.typecons, std.math, std.container, std.format, std.numeric;
alias T = Tuple!(long, "value", long, "time");
class Segtree
{
private:
long size;
T[] xs;
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
std.typecons, std.math, std.container, std.format, std.numeric;
alias T = Tuple!(long, "time", long, "value");
class Segtree
{
private:
T[] xs;
long size;
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
std.typecons, std.math, std.container, std.format, std.numeric;
struct SplayNode
{
public:
SplayNode* parent, left, right;
long size;
long value, minimum;
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
std.typecons, std.math, std.container, std.format, std.numeric;
struct SplayNode
{
public:
long size;
long x, minimum;
SplayNode* parent, left, right;
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
std.typecons, std.math, std.container, std.format, std.numeric;
class SegmentTree
{
private:
long[] xs;
long size;
public:
this(long size)
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
std.typecons, std.math, std.container, std.format, std.numeric;
alias T = Tuple!(long, "value", long, "time");
class SegmentTree
{
private:
T[] xs;
long size;