Skip to content

Instantly share code, notes, and snippets.

@jmg292
jmg292 / RC4.pyx
Created October 9, 2018 19:34
RC4 + Adler32 checksum implemented in Cython
from libc.string cimport strlen
cdef class RC4:
cdef list _sbox
cdef bytes _key
def __init__(self, char* key):
cdef int index = 0
self._sbox = list(range(256))
self._key = bytes(key)
@jmg292
jmg292 / TempManager.py
Created September 4, 2018 15:34
Creating a transparently encrypted RAM disk in Python using dm-crypt. Pointless but neat.
import os
import uuid
import Command
import subprocess
from Security import AccessLevels
from Command.BaseCommand import BaseCommand
from Command.Server.DriveUtility import DriveUtility
from Configuration.BaseConfiguration import BaseConfiguration
@jmg292
jmg292 / JsGiffer.py
Last active August 16, 2018 15:23
A pure Python utility to embed JavaScript within a gif.
class JsGiffer:
def __init__(self, image_file, script_file):
self._image_file = image_file
self._script_file = script_file
# Defines the gif header. "GIF89a" in ASCII
self._gif_header = b"\x47\x49\x46\x38\x39\x61"
# Sets the gif height and width. "/*/*" in ASCII. Wraps the gif content in a JavaScript comment
self._gif_header += b"\x2f\x2a\x2f\x2a"
# Defines the Javascript comment closing tag use for this gif. "*/" in ASCII
import sys
import time
import socket
class RC4:
def __init__(self, key):
self.key = [ord(c) for c in key]
self._sbox = []
@jmg292
jmg292 / TransportSecurity.go
Last active August 16, 2018 15:41
I don't remember what I used this for, but it's pretty neat.
package TransportSecurity
import "io"
import "math/big"
import "crypto/aes"
import "crypto/rand"
import "crypto/sha512"
import "crypto/cipher"
import "crypto/elliptic"
import "encoding/base64"
@jmg292
jmg292 / ECDHE.go
Last active August 16, 2018 15:40
An implementation of the elliptic curve Diffie-Hellman key exchange algorithm in Go.
package main
import "fmt"
import "math/big"
import "crypto/rand"
import "crypto/elliptic"
import "encoding/base64"
type HandshakeObj struct {
@jmg292
jmg292 / PowerShell-RC6.ps1
Last active August 16, 2018 15:33
A pure-PowerShell implementation of the RC6 cipher using the OCB mode of operation
<#
This script contains a pure PowerShell implementation of AEAD_RC6_32/20/32_OCB_TAGLEN128
Full specifications, RFCs, and other additional information is provided in the comments
as-needed in the form of links to the original documents.
#>
# Set ErrorActionPreference to STOP to ensure PowerShell terminates on encountering an exception
# $ErrorActionPreference = "STOP"
# XOR function designed to work with the 128-bit blocks used by OCB