Skip to content

Instantly share code, notes, and snippets.

@amtal
amtal / octree.clj
Created August 12, 2011 01:46
Start of LFErlang octree implementation
(defmodule octree
(export all))
(include-file "all2.lfe") ; lfe_utils library
;; Vectors:
(defmacro :vec3 ((x y z) `(tuple 'vec3 ,x ,y ,z)))
(defn :+ [(:vec3 x y z) (:vec3 a b c)]
@amtal
amtal / test_relup.erl
Created August 30, 2011 23:55
Check that a release upgrade works and touches the expected applications.
Rel=fun(Vsn) ->
release_handler:unpack_release("eg_"++Vsn),
A = application:which_applications(),
{ok,OldVsn,[]} = release_handler:install_release(Vsn),
B = application:which_applications(),
Delta = lists:zip(A--B,B--A),
[{relup,OldVsn,Vsn}
,{appups,[{App,From,To}||{{App,_,From},{App,_,To}}<-Delta]}
]
end.
@amtal
amtal / fileop.erl
Created September 25, 2011 00:37
Monad example in Erlang.
-module(fileop).
-export([write_file/3]).
-compile({parse_transform,do}).
%% Uses an error monad to neatly compose a bunch of failing functions.
%%
%% Everything being composed returns ok|{ok,Result}|{error,Reason}. At
%% the first error, the reason term is returned. The monad factors out
%% the behaviour of piping all possible errors to the output (via a
%% try-throw or case tree) if they occur.
@amtal
amtal / rpn.erl
Created September 25, 2011 04:10
Simple interpreter using a monad for a "mutable" environment.
-module(rpn).
-export([eval/1, hypotenuse/2]).
-compile({parse_transform,do}).
-spec eval([Op]) -> stack_m(ok).
%% Interpreter for a simple stack-based language.
%%
%% Uses a custom stack_m monad, which is a trivial wrapper around state_m[1].
%% It exports:
%% -spec pop() -> stack_m(A).
@amtal
amtal / Instructions.hs
Created April 5, 2012 04:55
0x10c DCPU-16 instruction set
-- | Complete abstract description of the DCPU-16 instruction set.
--
-- Based on Version 1.1 of the DCPU-16 Specification by Mojang, retrieved from 0x10c.com.
--
-- Contains a trivial "Label" extension, which isn't present in machine code
-- but is useful for dealing with assembly.
module DCPU16.Instructions where
import Data.Word hiding (Word)
import Data.ByteString
@amtal
amtal / gist:2327355
Created April 7, 2012 10:39
DCPU16 obfuscator/trick showcase/interpreter acid test.
; Code Obfuscator
;
; The loader has nice properties shorter versions don't:
; 1. doesn't touch registers or stack
; 2. can be based anywhere via 'set a,stub'
; 3. exercises interpreters ;)
:stub xor [begin],0x5eed
mul [2+a],25173 ; Grogono LCG
add [2+a],13849
add [1+a],1
@amtal
amtal / microcode.hex
Created July 16, 2012 05:07
p starts at 0x50, 12-byte steps, sanity-check starts at 0x5c
augur@niflheim:~/code/c/weird$ xxd -c12 -g4 -s8 dump.bin | more
0000008: 204a442e 20666f72 20496e74 JD. for Int
0000014: 656c2043 6f726520 32204475 el Core 2 Du
0000020: 6f205435 3735300d 0a286329 o T5750..(c)
000002c: 2053656c 656e612f 2f323030 Selena//200
0000038: 372c2032 30303800 2b000000 7, 2008.+...
0000044: 05000000 26000000 3e000000 ....&...>...
0000050: 47020000 e7fdffff 00000000 G...........
000005c: a3ffffff a7ffffff 01000000 ............
0000068: 02000000 0a000000 02000000 ............
@amtal
amtal / communications_extraterrestrial_intelligence.py
Last active December 23, 2015 08:29
NSA technical journal: reverse cryptanalysis/universal communication puzzle (Figure 3 typeset, also spoilers you may not want)
# based on http://www.nsa.gov/public_info/_files/tech_journals/communications_extraterrestrial_intelligence.pdf
# two related documents I know of:
# just message, shorter alphabet, longer: http://www.nsa.gov/public_info/_files/tech_journals/extraterrestrial_intelligence.pdf
# solutions: http://www.nsa.gov/public_info/_files/tech_journals/extraterrestrial_messages.pdf
"""
(1) A. B. C. D. E. F. G. H. I. J. K. L. M. N. O. P. Q. R. S. T. U. V. W. X. Y.
Z. *. &. $. ^. #. @. A. B. C. D. E. F. G. H. I. J. K. L. M. N. O. P.
Q. R. S. T. U. V. W. X. Y. Z. *. &. $. ^. #. @.
(2) A A, B; A A A, C; A A A A, D; A A A A A, E; A A A A A A, F;
A A A A A A A, G; A A A A A A A A, H; A A A A A A A A A, I;
#!/usr/bin/env python3
"""Usage: vimcrypt.py [FILE]...
Guesses first 64 bytes of vim-encrypted files. Method implemented is sufficient
for plain English (preferably with lots of spaces), but any knowledge of
underlying plaintext would do.
Example:
$ ./vimcrypt.py 1.txt 2.txt 3.txt 4.txt
"""Looking for collisions in Mooltipass "TRNG" output.
The "TRNG" outputs 32 bit blocks whitened with Jenkins one at a time hash,
keeping no state between samples. Running ent or diehard on the output stream
produces a predictable "pass" result, since these tests do not take the 32 bit
block structure into account.
Excessive collisions found by the following test would disprove the null
hypothesis that each 32 bit sample from the "TRNG" is uniformly distributed.