Skip to content

Instantly share code, notes, and snippets.

hi DiffAdd ctermfg=7 ctermbg=4
hi DiffChange ctermfg=7 ctermbg=4
hi DiffDelete ctermfg=7 ctermbg=4
hi DiffText ctermfg=7 ctermbg=1
@alexwebr
alexwebr / bad_strncpy.c
Last active May 11, 2016 16:41
Bad use of strncpy()
#include <string.h>
#include <stdio.h>
#include <assert.h>
// Find this with:
// git grep 'strncpy(\([^,]\+\), [^,]\+, sizeof(\1));'
int main(int argc, char *argv[])
{
// Take a single string argument
@alexwebr
alexwebr / dust_in_the_wind.rb
Created July 2, 2015 21:58
dust_in_the_wind.rb
# Iterates through its elements, starting at the beginning, forever.
class CircularList
def initialize values
@values = values
@index = 0
end
def next
value = @values[@index]
@index += 1
@alexwebr
alexwebr / brightness.c
Last active August 29, 2015 14:14
Mark this as setuid and put in your path, call with 'up' or 'down' to adjust your laptop's brightness.
#include <stdio.h>
const char *path = "/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS6208:00/backlight/toshiba/brightness";
int main(int argc, char *argv[])
{
if (argc != 2) {
fputs("Need exactly one argument", stderr);
return 1;
}

What's this all about?

Digital cryptography! This is a subject I've been interested in since taking a class with Prof. Fred Schneider back in college. Articles pop up on Hacker News fairly often that pique my interest and this technique is the result of one of them.

Specifically, this is about Lamport signatures. There are many signature algorithms (ECDSA and RSA are the most commonly used) but Lamport signatures are unique because they are formed using a hash function. Many cryptographers believe that this makes them resistant to attacks made possible by quantum computers.

How does a Lamport Signature work?

@alexwebr
alexwebr / gist:8347140
Last active January 2, 2016 18:59
Recursively frees a singly-linked tree structure (each node has a child, a first sibling, or both)
// [... snip ...]
void free_tree(tree_t *p)
{
if (p->sibling != NULL) {
free_tree(p->sibling);
p->sibling = NULL;
}
if (p->child != NULL) {