Skip to content

Instantly share code, notes, and snippets.

Nathaniel McHugh natmchugh

Block or report user

Report or block natmchugh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@natmchugh
natmchugh / soroban.py
Created Nov 23, 2016
Script what I wrote to learn to recognise numbers on a soroban
View soroban.py
import re, random, operator
random.seed()
def get_random_int():
return random.randint(1,999)
def to_soroban(number):
digits = {
0: "**** || *",
1: "*** *|| *",
View number_wang.py
import random, operator
random.seed()
def get_random_int():
return random.randint(2, 12)
numberOfQs = 10
ops = {"+": operator.add,
"-": operator.sub,
"*": operator.mul,
@natmchugh
natmchugh / fast_reverse.c
Created Oct 4, 2016
get the internal state from a PHP lcg in 3 outputs
View fast_reverse.c
/*
*
*/
#include <stdio.h>
#include <math.h>
#define MODMULT(a, b, c, m, s) q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m;
/* MODMULT computes s*b mod m, provided that m=a*b+c and 0<=c<m */
@natmchugh
natmchugh / lcg.php
Created Feb 23, 2016
Brute forcing the seeding of PHP's lcg
View lcg.php
<?php
class Lcg
{
private $s1 = 0;
private $s2 = 0;
public function __construct($s1, $s2)
{
$this->s1 = $s1;
@natmchugh
natmchugh / MersenneTwister.php
Created Feb 18, 2016
Pure PHP implementation of mt19937 with standard or PHP behaviours
View MersenneTwister.php
<?php
class MersenneTwister
{
const STANDARD = 1;
const PHP = 2;
// Create a length 624 array to store the state of the generator
private $MT;
@natmchugh
natmchugh / unseeded_mt_rand.php
Last active Jan 30, 2018
An example of how to guess the seed used in first call to PHP's mt_rand()
View unseeded_mt_rand.php
$time = time(0);
$pid = getmypid();
echo 'time is: ',$time,' (just the unix timestamp so very guessable)',PHP_EOL;
echo 'pid is: ',$pid, ' (process id of current PHP process usually in 1000s )',PHP_EOL;
$rand = mt_rand();
echo 'Output of 1st call to uninitialized to mt_rand is: '.$rand,PHP_EOL;
echo 'Output of 2nd call to uninitialized to mt_rand is: '.mt_rand(),PHP_EOL;
echo 'Output of 3rd call to uninitialized to mt_rand is: '.mt_rand(),PHP_EOL;
echo 'Guessing the seed now: ',PHP_EOL;
@natmchugh
natmchugh / kangaroo_ecc.py
Created Jan 21, 2016
Using Pollards Kangaroo on an Weierstrass curve
View kangaroo_ecc.py
import random
from Ecc import Ecc
from Ecc import Point
A = -95051
B = 11279326
p = 233970423115425145524320034830162017933
q = 233970423115425145498902418297807005944
ecc = Ecc(A, B, p)
@natmchugh
natmchugh / Montgomery.py
Created Jan 12, 2016
Montgomery Ladder
View Montgomery.py
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
View Q57.py
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 Nov 11, 2015
A MersenneTwister implementation that gives the same values as PHP's internal value
View MersenneTwister.php
<?php
class MersenneTwister
{
// Create a length 624 array to store the state of the generator
private $MT;
private $index;
public function __construct($seed)
You can’t perform that action at this time.