Skip to content

Instantly share code, notes, and snippets.

View thomdixon's full-sized avatar
👺

Thom Dixon thomdixon

👺
View GitHub Profile
@thomdixon
thomdixon / ssh_certificate.py
Last active October 14, 2021 10:25
Simple implementation of SSH certificates for Python using Paramiko. Supports serializing from and to Message objects.
from collections import OrderedDict
import paramiko
from paramiko.agent import AgentKey
from paramiko.message import Message
CERT_ATTRIBUTE_TO_TYPE = {
'name': 'string',
'nonce': 'string',
@thomdixon
thomdixon / ExponentialBackoff.py
Created September 30, 2016 21:50
Simple exponential backoff iterator
class ExponentialBackoff(object):
'''
Simple iterator that calculates exponential backoff durations
'''
def __init__(self, *args, **kwargs):
self.initial_interval = kwargs.pop('initial_interval', 5)
self.max_interval = kwargs.pop('max_interval', 60)
self.randomization_factor = kwargs.pop('randomization_factor', 0.5)
self.multiplier = kwargs.pop('multiplier', 1.5)
self.max_elapsed_time = kwargs.pop('max_elapsed_time', 900)
@thomdixon
thomdixon / PollardRho.py
Last active March 27, 2021 22:05
Pollard's rho algorithm in Python
#!/usr/bin/env python
from fractions import gcd
def pollard_rho(n, seed=2, f=lambda x: x**2 + 1):
x, y, d = seed, seed, 1
while d == 1:
x = f(x) % n
y = f(f(y)) % n
d = gcd((x - y) % n, n)
@thomdixon
thomdixon / NaiveRSA.py
Created February 28, 2013 02:19
Naive implementation of the RSA cryptosystem
import os
import random
class NaiveRSA(object):
_small_primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,
101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,
181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,
271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,
373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,
463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,
@thomdixon
thomdixon / NaiveDiffieHellman.py
Last active December 14, 2015 04:18
Naive (educational) implementation of the Diffie-Hellman(-Merkle) key exchange.
#!/usr/bin/env python
import os
class NaiveDiffieHellman(object):
'''Naive implementation of the Diffie-Hellman key exchange'''
# 3072 bit prime modulus and generator given in RFC3526
# this mod p group has id 14
__P = ('0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1'
'29024E088A67CC74020BBEA63B139B22514A08798E3404DD'