Skip to content

Instantly share code, notes, and snippets.

View lou1306's full-sized avatar

Luca Di Stefano lou1306

View GitHub Profile

Keybase proof

I hereby claim:

  • I am lou1306 on github.
  • I am lou1306 (https://keybase.io/lou1306) on keybase.
  • I have a public key ASDnyAjSj1cXM6LxSqVr5hIFJxPLxe0KNLLm8cFi1kTWSQo

To claim this, I am signing this object:

@lou1306
lou1306 / tuple.c
Last active January 11, 2018 14:17
Packing two integers inside a single `int`
#include "stdio.h"
#include "stdlib.h"
#define W 15 // Bit-Width of tuple elements (Up to 15 is fine)
const int MASK = (1U << W) - 1;
const int MASK2W = (1U << 2*W) - 1;
const int m = 1U << (W - 1);
/**
* @brief Trim n into bit-width W.
@lou1306
lou1306 / wiener.py
Created December 13, 2017 14:56
Wiener's RSA Attack
from fractions import gcd, Fraction
def intSqrt(n):
"""
Computes the integer square root of n, i.e.
the greatest x : x*x <= n
"""
x = n
y = (x + n // x) // 2
@lou1306
lou1306 / exchange.py
Last active July 10, 2017 11:13
People exchanging money with random others
from random import random
import matplotlib.pyplot as plt
PLAYERS = 100
WEALTH = 100
ROUNDS = 5000
MAX_PERCENT = 20
def myrandrange(start, stop):