Skip to content

Instantly share code, notes, and snippets.

! Flexoki color scheme for the X Window System
!
! https://stephango.com/flexoki
! Dark Tones
#define yellow #AD8301
#define orange #BC5215
#define red #AF3029
#define magenta #A02F6F
#define violet #5E409D
@dmb2
dmb2 / .stumpwmrc
Created October 16, 2012 19:41
My Stumpwmrc
;; -*-lisp-*-
;; .stumpwmrc
;; Author: David Bjergaard <dbjergaard@gmail.com>
;; License: GPL
;; Modeled off of gwern's stumpwmrc file at: http:en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(in-package :stumpwm)
;(load "/home/dave/builds/stumpwm/contrib/surfraw.lisp")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@dmb2
dmb2 / .stumpwmrc
Created February 2, 2014 22:49
Bill Zimmerly's stumpwmrc
;;;; -*- Mode: Lisp -*-
;; 20130620 (WBZ) This version of my .stumpwmrc is the culmination
;; of several days of study, experimentation, and asking of help
;; from others. (Beginning on 20130609.)
;;
;; This file is called "~/bin/stump/my.stumpwmrc" and is symbolically
;; linked as follows:
;;
;; $ cd; ln -s ~/bin/stump/my.stumpwmrc .stumpwmrc
@dmb2
dmb2 / create-hist.C
Created March 17, 2013 22:18
Two macros that open a root file and save a histogram. The other one opens a root file, retrieves a histogram, and fits a function to it.
{
float binWeights[12]={180,135,120,105,76,68,60,41,30,35,26,18};
TH1F kDecayHist("kDecayHist", "Decay length of K^{0} decays;decay length(cm);events",12,0,60);
for(int i=0; i < kDecayHist.GetNbinsX(); ++i){
kDecayHist.SetBinContent(i+1,binWeights[i]);
}
//recreate overwrites any old files and puts our new stuff inside without warning!
TFile f("kaondecay.root","RECREATE");
;;; lab-notebook.el -- Helper functions to publish a lab notebook with
;;; org-mode and jekyll
;; Copyright (C) 2013 David Bjergaard
;; Author: David Bjergaard <dbjergaard@gmail.com>
;; Keywords: log, lab notebook, org-mode, jekyll, github
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
class StreamCrypto
def self.aes_ctr_encrypt(clear_text,nonce,key)
counter=nonce.unpack('q')[0]
keystream = ""
cipher = OpenSSL::Cipher.new 'aes128'
cipher.padding=0
cipher.encrypt
cipher.key=key
(Float(clear_text.length)/key.length).ceil().times do
stream_nonce="\0"*8+[counter].pack('q')
@dmb2
dmb2 / gist:e6c7e9d2f77485e57f5a
Last active August 29, 2015 14:24
pkcs7 pad/strip
class String
def pkcs7strip
str=self.clone
# look at the last byte to determine padding amount
nbytes=str.bytes[-1]
# look at length-nbytes and make sure that it is also nbytes
# slice off nbytes and verify that each on is nbytes
if str.bytes[-nbytes] != nbytes
raise EncodingError,"Invalid PKCS7 Padding"
end
def challenge17
server = CBCPaddingServer.new
iv,session_cookie = server.get_session_cookie()
block_size=16
puts session_cookie.blocks(block_size).length
blocks=session_cookie.blocks(block_size)
blocks=[iv]+blocks
decoded_byte_string=[]
1.upto(blocks.length-1) do |bi|
decoded_bytes=[]
# Cipher text is a bytestring
# bi is the block index, or which block to edit. Flipping a bit in this block will result in a one bit edit in the bi+1 plaintext block
# i is the targeted bit's index
# z is the array of decoded bytes.
# The idea here is to target bit i, but also flip the bits of previously discovered bytes.
def flip_bit(cipher_text,bi,i,z)
bsize=16
i.times do |j|
tb=(z[j-1]==nil) ? 0 : z[j-1]
cb=cipher_text.bytes()[bi*bsize-j-1]
@dmb2
dmb2 / xor_byte_str.rb
Created May 28, 2015 20:58
Xor two strings, assumes you've got a Converters class that converts the bytestring to hex first.
class CryptoTools
def self.xor_str(str_a,str_b)
if str_a.length != str_b.length
raise "Length of input strings doesn't match!"
end
str_a.bytes.zip(str_b.bytes).map{ |x,y| x^y }.pack("C*")
end
def self.hex_xor(hex_a,hex_b)
Converters.str_to_hex(xor_str(Converters.hex_to_bytes(hex_a),
Converters.hex_to_bytes(hex_b)))