Skip to content

Instantly share code, notes, and snippets.

View natmchugh's full-sized avatar

Nathaniel McHugh natmchugh

View GitHub Profile
@natmchugh
natmchugh / Montgomery.py
Created January 12, 2016 21:08
Montgomery Ladder
import random
class Montgomery:
# B*v^2 = u^3 + A*u^2 + u
def __init__(self, A, B, p):
self.A = A
self.B = B
self.p = p
import random, hashlib, hmac, binascii, math
from Crypto.Cipher import AES
def encryptAndMac(K, message):
key = integerToAscii(K).zfill(16)
encryption_suite = AES.new(key[0:16], AES.MODE_CBC, 'YELLOW SUBMARINE')
padLength = 16 * int(math.ceil(float(len(message)) / 16))
cipher_text = encryption_suite.encrypt(message.zfill(padLength))
return [cipher_text, hmac.new(key, message, hashlib.sha1).digest()]
@natmchugh
natmchugh / MersenneTwister.php
Last active November 11, 2015 07:35
A MersenneTwister implementation that gives the same values as PHP's internal value
<?php
class MersenneTwister
{
// Create a length 624 array to store the state of the generator
private $MT;
private $index;
public function __construct($seed)
@natmchugh
natmchugh / php_mt.py
Last active November 10, 2015 15:23
Python implementation of the err interesting PHP internal implementation of mt_rand
def _int32(x):
# Get the 32 least significant bits.
return int(0xFFFFFFFF & x)
class MT19937:
def __init__(self, seed):
# Initialize the index to 0
self.index = 624
self.mt = [0] * 624
@natmchugh
natmchugh / cokus.c
Created November 10, 2015 11:52
Direct copy of PHP Mersenne twister implementation to get same numbers
// This is the ``Mersenne Twister'' random number generator MT19937, which
// generates pseudorandom integers uniformly distributed in 0..(2^32 - 1)
// starting from any odd seed in 0..(2^32 - 1). This version is a recode
// by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by
// Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in
// July-August 1997).
//
// Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha
// running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to
// generate 300 million random numbers; after recoding: 24.0 sec. for the same
@natmchugh
natmchugh / sha0_collsion.py
Last active October 22, 2015 15:36
This is a 2 block collision in sha0 from work New Disturbance Vector for SHA-0 Collision* by SHUANG WU, DENG-GUO FENG AND WEN-LING WU downloaded here http://www.iis.sinica.edu.tw/page/jise/2010/201011_13.pdf
import struct, binascii
def _left_rotate(n, b):
return ((n << b) | (n >> (32 - b))) & 0xffffffff
def sha0(message):
IV = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
# Initialize variables:
(h0, h1, h2, h3, h4) = IV
@natmchugh
natmchugh / sha1_freestart.py
Last active October 9, 2015 16:12
Python version of a quick check of the Freestart collision published here https://sites.google.com/site/itstheshappening/
import struct, binascii
def _left_rotate(n, b):
return ((n << b) | (n >> (32 - b))) & 0xffffffff
def sha1(IV, message):
# Initialize variables:
(h0, h1, h2, h3, h4) = IV
# Pre-processing:
@natmchugh
natmchugh / sha1_freestart.php
Last active October 9, 2015 14:54
Check that the Freestart collision published here https://sites.google.com/site/itstheshappening/ probably only works on 64 bit machine / OS
<?php
/*
Note 1: All variables are unsigned 32 bits and wrap modulo 232 when calculating, except
ml the message length which is 64 bits, and
hh the message digest which is 160 bits.
Note 2: All constants in this pseudo code are in big endian.
Within each word, the most significant byte is stored in the leftmost byte position
*/
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD74ICRUoaAXkRwqGW51botLrFygSC1SN3C7NR6cfFmpSdRuXZt6d20+GvAzOQKJpPTItK3YRjds1izapCqSM6o/BYWOikTKLHgzJ2s5Lwm6MZnPsnRJ1o+KbnXCytCrj3wFCcaS0Re+TJrlPvXggFZlane2yMit2rWx/FbFy44wNzsJLIGTIhsz6UnfmR7Wi7GfiMZ2p68xX3rSHJ3lNPTOzWfg/PFgc2YftzUow1TQ5xaamyPRD/UOXBOj2pfCp75v3TWDwwq3qliBV6pxUhe/ou8ut1zaRET5VTN4kFNziQZoxY4WVmCnCJxjBPt71hM9VzoujZggRNXct8uPdri hostname
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD74ICRUoaAXkRwqGW51botLrFygSC1SN3C7NR6cfFmpSdRuXZt6d20+GvAzOQKJpPTItK3YRjds1izapAqSM6o/BYWOikTKLHgzJ2s5Lwm6MZnPsnRJ9o9KbnXCytCrj3wFCcay0Re+TJrlPvXggFZlane2yMit2rWx/Fbly44wNzsJLIGTIhsz6UnfmR7Wi7GfiMZ2p48xn3rSHJ3lNPTOzWfg3PFgc2YftzUow1TQ5xaamyPRD/UOXBOj2pfCp75v3TWDwwq3qliBV6pxUhe/ou8ut1zaRET5VTN4kFNziQZoxY4WVmCnCJxjBPt71hM9VzoujZggRNXct8uPdri hostname