Skip to content

Instantly share code, notes, and snippets.

@chiiph
chiiph / defer.cpp
Created December 26, 2012 20:19
Defer implementation in C++
#include <iostream>
#include <functional>
#include <stack>
class Deferrer
{
public:
Deferrer() {}
~Deferrer() { callAll(); }
@chiiph
chiiph / chacha20.py
Created October 6, 2013 16:04
Python implementation of the stream cipher ChaCha20. The idea is to use numpy as the "numeric backend" to avoid side channel attacks. THIS IS JUST AN EXPERIMENT, DO NOT USE IN PRODUCTION.
# Based on http://cr.yp.to/streamciphers/timings/estreambench/submissions/salsa20/chacha8/ref/chacha.c
import binascii
import numpy as np
np.seterr(over='ignore')
def rotl32(v, c):
assert isinstance(v, np.uint32)
assert isinstance(c, np.uint32)
@chiiph
chiiph / leak.py
Created December 1, 2013 01:44
Proof of concept wanna be for Python's timing leaks
import os
import time
import gc
gc.disable()
def const_cmp(str1, str2):
res = len(str1) ^ len(str2)
for a, b in zip(str1, str2):
res |= ord(a) ^ ord(b)
PyObject* signalInstanceEmit(PyObject* self, PyObject* args)
{
PySideSignalInstance* source = reinterpret_cast(self);
Shiboken::AutoDecRef pyArgs(PyList_New(0));
Shiboken::AutoDecRef sourceSignature(PySide::Signal::buildQtCompatible(source->d->signature));
PyList_Append(pyArgs, sourceSignature);
for (Py_ssize_t i = 0, max = PyTuple_Size(args); i d->source, "emit"));
import sys
import logging
from functools import partial
from PySide import QtCore, QtGui
class Obj(QtCore.QObject, logging.Handler):
sig = QtCore.Signal(dict)
def __init__(self):
from leap.soledad import Soledad
import logging
level = logging.DEBUG
logger = logging.getLogger(name='leap')
logger.setLevel(level)
console = logging.StreamHandler()
console.setLevel(level)
import sys
import telnetlib
if __name__ == "__main__":
mail = {
"from": sys.argv[1],
"to": sys.argv[2],
"subject": sys.argv[3],
"msg": sys.argv[4]
class Base
{
public:
Base() {}
virtual ~Base() {}
};
class NotCopyable
{
public:
class FirstComponent(object):
def __init__(self, parent):
object.__init__()
parent.someFunc = self.someFunc
def someFunc(self):
return 42
class GameObject(object):
def __init__(self):
@chiiph
chiiph / defer.go
Created December 26, 2012 20:14
Defer example in Go
func CopyFile(dstName, srcName string) (written int64, err error) {
src, err := os.Open(srcName)
if err != nil {
return
}
defer src.Close()
dst, err := os.Create(dstName)
if err != nil {
return