Skip to content

Instantly share code, notes, and snippets.

@adoc
adoc / pkcs7.py
Last active July 25, 2021 09:46
#pkcs7.py3: Implementation of PKCS #7 padding. Based on: http://japrogbits.blogspot.com/2011/02/using-encrypted-data-between-python-and.html
"""
Python implementation of PKCS #7 padding.
RFC 2315: PKCS#7 page 21
Some content-encryption algorithms assume the
input length is a multiple of k octets, where k > 1, and
let the application define a method for handling inputs
whose lengths are not a multiple of k octets. For such
algorithms, the method shall be to pad the input at the
trailing end with k - (l mod k) octets all having value k -
@adoc
adoc / aes.py
Last active January 4, 2016 01:59
aes.py3: Simple AES helper
"""
"""
from Crypto import Random
from Crypto.Cipher import AES
import pkcs7
random = Random.new().read
@adoc
adoc / whmac.py
Last active January 4, 2016 01:59
whmac.py3: Convenient HMAC wrappers.
"""
whmac.py3
Convenient HMAC wrappers.
Author: github.com/adoc
Location: https://gist.github.com/adoc/8552289
"""
@adoc
adoc / message.py
Last active January 4, 2016 02:09
message.py3: Simple class to combine a signer and/or cipher to "authenticate" a message `payload`.(Use with whmac and aes in this gist.)
"""
Several Messaging classes, building blocks and helpers.
Author: github.com/adoc
"""
import os
import base64
import json as _json
import functools
@adoc
adoc / wrapper.js
Created January 25, 2014 03:34
wrapper.js: Convenient JS Package wrapping that also will hook require.js if present.
/*
Convenient JS Package wrapping that also will hook require.js if present.
*/
(function(window) {
// Your package goes here.
var MyPackage = {};
// Set global object.
window.MyPackage = MyPackage;
@adoc
adoc / hmac.js
Last active January 4, 2016 10:49
hmac.js: Using CryptoJS, implements HMAC algorithm while also hashing and appending timestamp information.
/*
hmac.js
Using CryptoJS, implements HMAC algorithm while also hashing and appending
timestamp information.
Author: github.com/adoc
Location: https://gist.github.com/adoc/8611494
*/
@adoc
adoc / cookies.js
Created January 25, 2014 03:51
cookies.js: Using cookie.js, adds some additional helpers to add/delete multiple cookies at one time. With JSON, also the ability to put objects in cookies.
/*
cookies.js
Using cookie.js, adds some additional helpers to add/delete multiple cookies
at one time. With JSON, also the ability to put objects in cookies.
Author: github.com/adoc
*/
(function(window) {
@adoc
adoc / cookie.js
Last active January 4, 2016 10:49
cookie.js: JavaScript cookie manipulation class
@adoc
adoc / rng.js
Created January 25, 2014 05:20
rng.js: Random number generator
//http://www-cs-students.stanford.edu/~tjw/jsbn/prng.js
// prng4.js - uses Arcfour as a PRNG
function Arcfour() {
this.i = 0;
this.j = 0;
this.S = new Array();
}
// Initialize arcfour context from key, an array of ints, each from [0..255]
@adoc
adoc / bytes.js
Created January 25, 2014 05:39
bytes.js: Just some functions to help out with byteArrays.
/*
Just some functions to help out with byteArrays.
Authors and Inspiration: github.com/adoc and Various Others.
*/
// Converts an integer to bytes.
var intToBytes = function(n) {
var result = '';
while (n) {