Skip to content

Instantly share code, notes, and snippets.

View jsanders's full-sized avatar

James Sanders jsanders

View GitHub Profile
@jsanders
jsanders / go.md
Created March 30, 2012 03:47
Newton's method go vs. ruby comparison
package main

import("fmt"; "math")

func Sqrt(x float64) (z float64) {
  z, delta := 1.0, 1.0

  for delta > 1e-4 {
    z0 := z
@jsanders
jsanders / xml.rs
Created April 4, 2012 02:13
Rust deserialize XML first crack
use std;
import io::reader_util;
enum node {
tag_node({
name: str,
attributes: [attribute],
children: [node]
}),
@jsanders
jsanders / failures.log
Last active January 25, 2016 08:00
Servo WebSocket test failures
▶ TIMEOUT [expected OK] /websockets/Create-Secure-extensions-empty.htm
▶ Unexpected subtest result in /websockets/Create-Secure-extensions-empty.htm:
└ NOTRUN [expected PASS] W3C WebSocket API - Create Secure WebSocket - wsocket.extensions should be set to '' after connection is established - Connection should be closed
▶ Unexpected subtest result in /websockets/Create-Secure-extensions-empty.htm:
│ FAIL [expected PASS] W3C WebSocket API - Create Secure WebSocket - wsocket.extensions should be set to '' after connection is established - Connection should be opened
│ → assert_equals: extensions should be empty expected (string) "" but got (undefined) undefined
│ @http://web-platform.test:8000/websockets/Create-Secure-extensions-empty.htm:9:13
@jsanders
jsanders / mod_exp.rs
Last active January 4, 2016 21:19
Rust extra::bigint mod_exp
// Modular exponentiation by squaring
fn mod_exp(base: &BigUint, exponent: &BigUint, modulus: &BigUint) -> BigUint {
let (zero, one): (BigUint, BigUint) = (Zero::zero(), One::one());
let mut result = one.clone();
let mut baseAcc = base.clone();
let mut exponentAcc = exponent.clone();
while exponentAcc > zero {
// Accumulate current base if current exponent bit is 1
if (exponent & one) == one {
@jsanders
jsanders / shellcode.asm
Last active December 26, 2015 04:56
Generally useful, well-documented, and small shellcode generator. Based on work I did for level05 of Stripe's original CTF, but much nicer.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A nice, small 32-bit x86 execve shellcode template. ;
; execve("//bin/sh", [ "//bin/sh", NULL ], [ NULL ]). ;
; Shellcode itself is 25 bytes. ;
; Provide definitions of PayloadSize and JumpAddress ;
; to generate a self-contained buffer of the desired ;
; size and with the desired address to jump to. ;
; Build with "nasm -f bin -o shellcode shellcode.asm" ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@jsanders
jsanders / glut_hello_world.cpp
Last active December 25, 2015 03:09
GLUT hello world implementations in c++ (for reference) and rust (as an attempt). The rust version seems close to working, but it hangs after the window comes up...
// Compile with `g++ -framework GLUT glut_hello_world.cpp`
#include <GLUT/glut.h>
void display(void) { }
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
@jsanders
jsanders / flip.rs
Last active December 24, 2015 10:38
Seeing if I can make a rust implementation of `flip` that is reminiscent of Haskell's (http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#v:flip)
fn flip<T>(f: ~fn(a: T, b: T)) -> ~fn(a: T, b: T) {
|a, b| { f(b, a) }
}
fn hello_world(hello: &str, world: &str) {
println!("{:s}, {:s}!", hello, world)
}
#[test]
fn test_flip() {
@jsanders
jsanders / redis.rs
Last active December 24, 2015 10:29
Start of redis client implementation in rust
use std::rt::io::{Reader, Writer};
use std::rt::io::net::ip::{Ipv4Addr,SocketAddr};
use std::rt::io::net::tcp::TcpStream;
use std::str;
trait ToUintSafe {
fn to_uint_safe(&self) -> Option<uint>;
}
impl ToUintSafe for int {
@jsanders
jsanders / invmod.rb
Created September 27, 2013 20:57
Modular inverse function, with obligatory EGCD implementation.
# Extended Euclidean GCD algorithm
# Outputs k, u, and v such that ua + vb = k where k is the gcd of a and b
def egcd(a, b)
u_a, v_a, u_b, v_b = [ 1, 0, 0, 1 ]
while a != 0
q = b / a
a, b = [ b - q*a, a ]
u_a, v_a, u_b, v_b = [ u_b - q*u_a, v_b - q*v_a, u_a, v_a ]
# Each time, `u_a*a' + v_a*b' = a` and `u_b*a' + v_b*b' = b`
end
@jsanders
jsanders / level06_exploit.py
Last active December 22, 2015 16:48
Exploit in python for level 6 of Stripe's first CTF.
from os import pipe, write, close
from subprocess import Popen, PIPE
import select
import string
import sys
PIPE_MAX = 1<<16 # 64k
WELCOME_LEN = len("Welcome to the password checker!\n")
def args(guess):