Skip to content

Instantly share code, notes, and snippets.

View maple3142's full-sized avatar

maple maple3142

  • Taiwan
  • 08:13 (UTC +08:00)
  • X @maple3142
View GitHub Profile
@maple3142
maple3142 / sample_output.txt
Created April 29, 2021 18:22
Four method to solve Truncated LCG (different use cases)
homogeneous (b=0), accurate
original [29267633625914, 119312469505830, 53136096702586, 77836329078246, 106460853890490, 166319733341350, 130263926313722, 174241440547686]
truncated [26, 108, 48, 70, 96, 151, 118, 158]
result [29267633625914, 119312469505830, 53136096702586, 77836329078246, 106460853890490, 166319733341350, 130263926313722, 174241440547686]
non homogeneous, using substitution with constant (works only if gcd(a-1, m)==1, and it might fails)
original [99102228030939, 44710696337531, 72519758320251, 142661241057915, 26385529352827, 189216876835451, 265000266150523, 197653568336507]
truncated [90, 40, 65, 129, 23, 172, 241, 179]
result [99102228030939, 44710696337531, 72519758320251, 142661241057915, 26385529352827, 189216876835451, 265000266150523, 197653568336507]
@maple3142
maple3142 / README.md
Last active June 15, 2025 02:28
Rootless Tailscale

Running tailscaled

Download static tailscaled binary here

TAILSCALED_SOCKET="/tmp2/$USER/tailscaled.sock"
TAILSCALED_STATE="tailscaled.state"
./tailscaled --tun=userspace-networking --state="$TAILSCALED_STATE" --socket "$TAILSCALED_SOCKET"
@maple3142
maple3142 / url-shortener.js
Last active June 12, 2025 10:05
url shortener for cf workers
addEventListener('fetch', (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
const ID_LEN = 6
const SEC_PER_DAY = 60 * 60 * 24
# padic ecdlp
# combines https://hackmd.io/@mitsu/ByhK-tZX_ and proposition 4 from https://arxiv.org/pdf/2010.15543
def gen_problem(p, k):
R = Zmod(p**k)
S = (randint(1, p), randint(1, p))
a1 = randint(1, p)
a2 = R(S[1] ** 2 - (S[0] ** 3 + a1 * S[0]))
E = EllipticCurve(R, [a1, a2])
@maple3142
maple3142 / README.md
Last active March 20, 2025 12:19
ctf python env
conda create --name ctf sage=10.5 -c conda-forge
pip install web3 pwntools numpy z3-solver httpx fastecdsa pytesseract pyshark flask-unsign flask-unsign[wordlist] binteger websockets pycryptodome ecdsa black gunicorn websockets waitress git-dumper ptrlib gunicorn[gevent] ropper tqdm flask r2pipe PyExifTool python-docx pillow numpy pycurl galois networkx pyshark gradient-free-optimizers bottle playwright
# also try z3-solver==4.11.2.0 which could be faster

# with more ml stuffs:
conda create --name ctf sage=10.2 -c conda-forge scikit-learn pandas pytorch matplotlib torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

# not supported by Python 3.11
# pip install cvc5
@maple3142
maple3142 / z3mt.py
Last active March 10, 2025 04:47
Breaking MT19937 with z3 with examples
from z3 import *
import random
from contextlib import contextmanager
from time import perf_counter
# ------------------
# Start of utility functions
# credits: @y011d4
# ------------------
@maple3142
maple3142 / README.md
Created February 28, 2025 03:46
vscode git signing & gpg tty pinentry

A workaround for people who prefer entering password in tty when possible (e.g. using pinentry-mode loopback) but don't want to break vscode commit signing:

  1. Create a ~/.local/bin/my-pinentry.sh:
#!/bin/sh
if [ "$PINENTRY_USER_DATA" = "tty" ]; then
    exec /usr/bin/pinentry-tty "$@"
else
    exec /usr/bin/pinentry "$@"
fi
@maple3142
maple3142 / asdf_shell.zsh
Created February 12, 2025 03:31
asdf shell for asdf 0.16.0+
asdf_shell() {
export "ASDF_${1:u}_VERSION"="$2"
}
# and completion for zsh assuming ASDF_DATA_DIR is set
_asdf_shell_1() {
local -a plugins=( "${ASDF_DATA_DIR:?}/plugins"/*(:t) )
compadd -a plugins
}
_asdf_shell_2() {
@maple3142
maple3142 / example.sage
Last active December 23, 2024 01:20
LLL/CVP utilities, now updated at https://github.com/maple3142/lll_cvp
from lll_cvp import *
from functools import partial
def example1():
# copied from https://github.com/rkm0959/Inequality_Solving_with_CVP/blob/main/Example%20Challenge%204%20-%20HITCON%20CTF%202019%20Quals%20-%20not%20so%20hard%20RSA/solve_challenge_4.sage
## Example 4 : HITCON CTF 2019 Quals not so hard RSA
## d is 465 bits
@maple3142
maple3142 / Dockerfile
Last active December 1, 2024 17:28
Sage + macaulay2 in docker
# Time usage: <5min
# Net usage: ~200MB
# Disk usage: <800MB docker image
FROM ubuntu:20.04
# Setting up Macaulay2 repository
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common apt-transport-https && \