Skip to content

Instantly share code, notes, and snippets.

View rmmh's full-sized avatar

Ryan Hitchman rmmh

  • Boulder, Colorado
View GitHub Profile
@rmmh
rmmh / bot_trust.py
Created May 9, 2011 02:46
Google Code Jam 2011 Prelim Round A
n_cases = input()
for case in xrange(1, n_cases + 1):
bot = {'O': [1, 0], 'B': [1, 0]}
buttons = raw_input().split()[1:]
buttons = zip(buttons[::2], map(int, buttons[1::2]))
time = 0
@rmmh
rmmh / 0x10c_radio_v1.txt
Created April 6, 2012 20:27
0x10c Radio Communications
0x10c Radio Communications
For each solar system, there are 256 channels.
Each channel holds 128 words of data, and gets reset to zeros 8 times per second.
A radio can broadcast 1-128 words once per second to any channel, and receive
1-128 words eight times per second from any channel.
Broadcasting XORs the sent data with the current contents of the channel.
//===-- DCPU16InstrFormats.td - DCPU16 Instruction Formats -*- tablegen -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
@rmmh
rmmh / A.mdown
Created April 9, 2012 04:36
DPCU-16 Spec Suggestions

DCPU-16 Spec Suggestions

  1. Evaluate b before a

This makes instructions that address the stack twice meaningful instead of confusing and useless.

ADD PEEK, POP should pop the top of the stack and add it to the second entry, but currently the PEEK is evaluated before the POP occurs.

  1. Add [SP+next word] addressing
@rmmh
rmmh / crack.py
Created May 5, 2012 02:30
0x10c ARG
lines = [x.strip() for x in open("seq.txt")]
while '0000' in lines:
# strip the time codes
i = lines.index('0000')
lines = lines[:i] + lines[i+4:]
subst = {'0590': " ", '22f2': "e", '1225': "a", '77ee': "t",
'9036': "h", '0817': "n", '5819': "d", '29d3': "o",
'4079': "g", 'f6de': "y", '906b': "m", '5bcd': "l",
@rmmh
rmmh / agents.js
Last active December 10, 2015 08:08
Gradient A-life Modifications that speed it up ~5x http://www.cs.mcgill.ca/~mcheva/gradient/gradient.html
/*****************************************************************************
*
* Gradient: an Artificial Life Experiment
* Copyright (C) 2011 Maxime Chevalier-Boisvert
*
* This file is part of Gradient.
*
* Gradient is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@rmmh
rmmh / gist:4615975
Last active September 22, 2022 16:54
iclicker id obfuscation
def enc(id1, id2, id3):
''' encrypt the first three bytes of the ID
* the 4th byte of the ID is id1 ^ id2 ^ id3
* the top three bits of id1 are lost, meaning
there are 2^21 ~= 2M unique clicker IDs
source: reversed iclicker1 firmware '''
a = (id1 & 0x1F) << 3
a |= (id2 & 0x80) >> 5
a |= maskFrom3rd(a)
@rmmh
rmmh / Makefile
Created February 7, 2013 21:41
Implicit makefile rules
SRCS=iGtalk.c friends.c
BIN=iGtalk
CC=gcc
CFLAGS=-g3 -DDEBUG=1 -I include
LDLIBS=-L lib -lgnutls -lgsasl -lrecv_xml_nonblock
OBJS=$(SRCS:.c=.o)
DEP=makefile.dep
@rmmh
rmmh / GitS_2013_RTFM.md
Last active December 13, 2015 22:18
GitS 2013 RTFM

I reverse engineered the binary to find the encoding function, converted it to Python, and verified correctness. I then wasted a bunch of time making an iterative bruteforcer, until I realized that the encoding function is basically equivalent to:

bits('RTFM') + tab[buf[0]] + '00' + tab[buf[1]] + '00' + ... + tab[buf[n]]

where tab is a mapping from ascii characters to variable-length bitstrings, with the important property that they start and end with 1s, and contain no 00s. (match /^1.*1$/ but not /00/)

After that, decoding is simple.

@rmmh
rmmh / hummingbird2.dasm
Last active December 13, 2015 23:19
DCPU16 Hummingbird-2 Implementation
SET A, plain
SET B, 8
SET C, key
SET X, iv
JSR crypt_hummingbird2_enc
SET A, plain
SET B, 8
SET C, key
SET X, iv