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
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)))
(defun hello-world (width height &optional (host ""))
(let* ((display (xlib:open-display host))
(screen (first (xlib:display-roots display)))
(black (xlib:screen-black-pixel screen))
(white (xlib:screen-white-pixel screen))
(root-window (xlib:screen-root screen))
(grackon (xlib:create-gcontext
:drawable root-window
:foreground white
:background black))
@dmb2
dmb2 / install-packages.el
Created September 8, 2014 14:16
Automatically install packages needed by the rest of init.el on a fresh computer.
(defun install-required-packages (package-list)
(when (>= emacs-major-version 24)
(package-refresh-contents)
(mapc (lambda (package)
(unless (require 'package nil t)
(package-install 'package)))
package-list)))
(setq required-package-list '(bm icicles smex zenburn-theme))
(install-required-packages required-package-list)
@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");