Skip to content

Instantly share code, notes, and snippets.

@resilar
resilar / ctz.c
Created June 15, 2016 13:59
de Bruijn CTZ with proper handling of 0
// you faggots probably know the de bruijn trick to count trailing zeros:
inline int ctz32_retarded(uint32_t x)
{
static const unsigned char debruijn_ctz32[32] = {
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
return debruijn_ctz32[((x & -x) * 0x077CB531) >> 27];
}
@resilar
resilar / zylom.c
Last active September 21, 2021 02:04
zylom trivial pursuit genus edition questions.dat.! (de)cryptor
#include <stdio.h>
static const unsigned char D[256] =
"\x3E\x29\xEB\x7F\x9E\xB9\x60\xC7\x8B\x18\x77\xA0\xD3\x35\xB5\x5F"
"\x44\x49\x1B\x74\xA3\x6A\xF5\xCD\x28\x88\x0C\x53\x01\xA4\xB6\x47"
"\x2E\x65\x9B\xC5\x83\x66\x10\x22\xDF\xFD\xD1\x70\x0A\xB1\x8A\xA9"
"\xF3\x21\x6B\x30\xF4\x27\xBC\x11\x15\xDD\xF7\xED\x48\xE1\x17\x9A"
"\x46\xC4\xB7\x6C\xD0\x91\xAA\x8E\xCC\xC6\x1F\x2C\x73\xDB\x5D\x71"
"\x1E\x6F\xFC\x33\xCA\x25\xF2\x4D\x0B\x1C\xF6\x06\xB8\x26\xC9\x36"
"\xB3\xE0\xBE\xD2\xDE\x67\xE6\x4F\x81\x3F\xF0\xD7\xC3\x00\x75\x6E"
@resilar
resilar / lyn.c
Created June 15, 2016 14:23
Lyndon factorization
/**
* Compute the Lyndon factorization of S[0..n-1].
* O(n) time and O(1) space blabla.
*
* ... because Duval's algorithm is a piece of shit.
*/
void lyn(unsigned char *S)
{
int u, v;
u = v = 0;
@resilar
resilar / Z.c
Last active February 9, 2024 11:34
Z algorithms
/**
* The Z array of a string S[0..n-1] gives for each suffix S[i..n-1],
* 0<=i<=n-1, the length of the longest common prefix with S. Example:
*
* i | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
* -----+---------------------------------------------------
* S[i] | a a a b a a b b a a a b a a a a b
* Z[i] | 17 2 1 0 2 1 0 0 6 2 1 0 3 4 2 1 0
*
* The Z algorithm computes the Z array in linear time, which has many
@resilar
resilar / tormap.py
Last active July 11, 2019 10:59
map(GET(url)) over Tor exit nodes
#!/usr/bin/env python
TORPROXY=("localhost", 9050)
CONTROLPORT=9051
COOKIE="/var/lib/tor/control_auth_cookie"
URL="http://showip.net"
OUT="scan/"
RELAY="firsthop"
EXITS="exit-addresses"
@resilar
resilar / spoiler.pl
Last active February 25, 2017 19:11
irssi script
use strict;
use warnings;
use Irssi;
our $VERSION = '0.0.6283185307';
our %IRSSI = (
authors => 'def',
contact => 'def <[email protected]>',
name => 'spoiler',
description => 'Colorize lines of idiots with black on black text',
@resilar
resilar / pam_badlog.c
Last active November 27, 2018 13:51
PAM module to log bad SSH passwords (for non-/home/ users only)
/*
* pam_badlog.c
*
* $ gcc -fPIC -fno-stack-protector -c pam_badlog.c
* $ sudo ld -x --shared -o /lib/security/pam_badlog.so pam_badlog.o
* $ rm pam_badlog.o
*
* then add "auth required pam_badlog.so" in the beginning of /etc/pam.d/sshd
*
* $ /etc/init.d/sshd restart
@resilar
resilar / pdlsym.c
Last active June 30, 2024 13:19
dlsym() for remote processes
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <unistd.h>
struct elf {
@resilar
resilar / opt.tex
Last active October 8, 2019 12:20
The *correct* way to typeset optimization problems in LaTeX
% Output: http://i.imgur.com/88G3s9V.png
\begin{equation}
\begin{split}
& \text{\large Primal} \\
\text{min } & \sum_{j=1}^s x_j + Bz \\
\text{s.t. } &
\begin{aligned}[t]
x_j + z &\ge 1 & \forall j = 1,2,\dots,s \\
x_j &\ge 0 & \forall j = 1,2,\dots,s \\
z &\ge 0
@resilar
resilar / execve.c
Created March 8, 2017 17:07
Linux x86(-64) - execve("/bin/sh", ["/bin/sh", 0], 0) shellcode (38 bytes)
/*
* Linux x86(-64) - execve("/bin/sh", ["/bin/sh", 0], 0) shellcode (38 bytes)
* 31c050488b1424eb105478065e5fb03b0f05595b40b00bcd80e8ebffffff2f62696e2f736800
*
* - offset - bytes 32-bit code 64-bit code
* 0x00000000 31c0 xor eax, eax xor eax, eax
* 0x00000002 50 push eax push rax
* 0x00000003 48 dec eax rex.w
* 0x00000004 8b1424 mov edx, dword [esp] mov rdx, qword [rsp]
* 0x00000007 eb10 jmp 0x19 jmp 0x19