Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / morsecode.c
Last active Nov 24, 2020
Morse code decoder automaton
View morsecode.c
/* Morse code decoder automaton
* This is free and unencumbered software released into the public domain.
*/
/* Advance to the next state for an input, '.', '-'. or 0 (terminal).
* The initial state is zero. Returns the next state, or the result:
* < 0 when more input is needed (i.e. next state)
* = 0 for invalid input
* > 0 the ASCII result
*/
@skeeto
skeeto / Makefile
Last active Nov 24, 2020
AI driving simulation
View Makefile
.POSIX:
CC = cc
CFLAGS = -Ofast -fopenmp -g -Wall -Wextra
LDFLAGS =
LDLIBS = -lm
aidrivers: aidrivers.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ aidrivers.c $(LDLIBS)
clean:
@skeeto
skeeto / sponge4.bas
Last active Nov 17, 2020
Sponge4 implemented in QBasic
View sponge4.bas
' Sponge4: a sponge construction based on RC4
' Ref: https://nullprogram.com/blog/2020/11/17/
' This is free and unencumbered software released into the public domain.
TYPE sponge4
i AS INTEGER
j AS INTEGER
k AS INTEGER
s(0 TO 255) AS INTEGER
END TYPE
@skeeto
skeeto / avalanche.c
Last active Nov 9, 2020
Avalanche matrix graphs for various hash functions
View avalanche.c
/* Avalanche matrix visualizer
* $ cc -Ofast -fopenmp -Wall -Wextra avalanche.c
* This is free and unencumbered software released into the public domain.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define NSAMPLES (1L << 24)
#define SCALE 24
@skeeto
skeeto / siphash.h
Last active Nov 24, 2020
SipHash implementation in portable C
View siphash.h
/* SipHash implementation in portable C
* This is free and unencumbered software released into the public domain.
* Ref: https://cr.yp.to/siphash/siphash-20120620.pdf
*/
#include <stddef.h>
#include <stdint.h>
static uint64_t
siphash(const void *buf, size_t len, uint64_t key0, uint64_t key1)
{
@skeeto
skeeto / arxseq64.c
Last active Nov 6, 2020
ARX-based PRNG
View arxseq64.c
/* ARX-based PRNG
* This is free and unencumbered software released into the public domain.
* Ref: https://github.com/danielnager/arxseq64
*/
#include <stdint.h>
static void
arxseq64(uint64_t b[8])
{
b[2] ^= b[0]; b[3] ^= b[1]; b[2] += b[1]; b[3] += b[0];
@skeeto
skeeto / cistercian.c
Created Nov 6, 2020
Cistercian Number System
View cistercian.c
/* Cistercian Number System -- renders all 0-9999
* $ cc -Os cistercian.c
* $ ./a.out | convert pgm:- cistercian.png
* Ref: https://www.youtube.com/watch?v=9p55Qgt7Ciw
*/
#include <stdio.h>
#include <string.h>
#define W 200
#define H 50
@skeeto
skeeto / keycount.c
Last active Nov 24, 2020
6x6 Hotel Key Card Counter
View keycount.c
/* 6x6 Hotel Key Card Counter
* $ cc -fopenmp -O3 -march=native keycount.c
* Ref: https://possiblywrong.wordpress.com/2020/10/24/counting-hotel-key-cards/
*/
#include <stdio.h>
static long long
transpose(long long x)
{
return (x << 5 & 0x408102040) |
View shut-the-box.c
// Shut-the-Box Monte Carlo method winning odds calculator.
//
// This simulation plays all possible strategies in parallel, reporting the
// percentage of winnable games.
// Ref: https://youtu.be/IRQiyXkoLAM
//
// This is free and unencumbered software released into the public domain.
#include <stdio.h>
#include <string.h>
@skeeto
skeeto / Makefile
Created Oct 7, 2020
Hexagon grid bitmap renderer
View Makefile
CC = cc
CFLAGS = -std=c99 -pedantic \
-Ofast -march=native \
-ggdb3 -fsanitize=address -fsanitize=undefined \
-Wall -Wextra -Wdouble-promotion
LDFLAGS = -fsanitize=address -fsanitize=undefined
LDLIBS = -lm
hexmap: hexmap.c bmp.h getopt.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ hexmap.c $(LDLIBS)
You can’t perform that action at this time.