Skip to content

Instantly share code, notes, and snippets.

View giannitedesco's full-sized avatar

Gianni Tedesco giannitedesco

View GitHub Profile
@giannitedesco
giannitedesco / hist.py
Created December 10, 2023 10:37
Boilerplate for histograms
#!/usr/bin/python
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
from math import log
from sys import argv
def hist(p: Path) -> None:
vals = [int(x) for x in p.read_text().splitlines()]
#!/usr/bin/env python3
__title__ = 'silverhand'
__description__ = 'breach protocol puzzle solver'
__copyright__ = 'Copyright 2020 Gianni Tedesco'
__author__ = 'Gianni Tedesco'
__author_email__ = 'gianni@scaramanga.co.uk'
__license__ = 'MIT'
from collections import defaultdict
@giannitedesco
giannitedesco / hibp.py
Last active December 14, 2020 09:17
Tool to check haveibeenpwnd password database
#!/usr/bin/python
__author__ = 'Gianni Tedesco'
__url__ = 'https://github.com/giannitedesco/'
__license__ = 'Public Domain'
from hashlib import sha1
from getpass import getpass
import httpx
@giannitedesco
giannitedesco / gash.py
Created August 30, 2018 08:13
Send secret messages to someone using their public ssh key
#!/usr/bin/python3
__copyright__ = "Copyright (c) 2018 Gianni Tedesco"
__licence__ = "GPLv3"
__doc__ = "Tool for sending secret messages using ssh keys"
from argparse import ArgumentParser
try:
import nacl.utils
from nacl.signing import SigningKey,VerifyKey
@giannitedesco
giannitedesco / readkeys.py
Created August 28, 2018 12:21
Parse openssh public and private keys, only ed25519
#!/usr/bin/python3
try:
from nacl.signing import SigningKey
_nacl = True
except:
_nacl = False
from base64 import b64decode
from struct import unpack
from iquery import IQuery
from entry import Entry
class IQueryFast(IQuery):
def __init__(self, sz, e):
super(IQueryFast, self).__init__(sz)
e = [x for x in e]
e.append(Entry(0, sz, None))
@giannitedesco
giannitedesco / poly.py
Created July 17, 2014 01:22
Take a list of numbers and find a polynomial function that describes them
#!/usr/bin/python
# vim: set fileencoding=utf8 :
import numpy as np
def finite_differences(y):
"Use method of finite differences to determine "
"what order of polynomial to look for"
inp = y[:]
@giannitedesco
giannitedesco / cmath.h
Created July 14, 2013 12:58
A minheap implementation in C. Does some pointer arithmetic to achieve one-based indexing without wasting memory. API amenable to static bounds checking.
/*
* This file is part of cola
* Copyright (c) 2013 Gianni Tedesco
* This program is released under the terms of the GNU GPL version 3
*/
#ifndef _CMATH_H
#define _CMATH_H
#include <bits/wordsize.h>
@giannitedesco
giannitedesco / minheap.py
Created July 14, 2013 11:12
Pure python implicit min-heap implementation that subclasses list. Includes efficient build-heap initialiser. Insert/Delete operations with pop() and append() methods.
#!/usr/bin/python
class Heap(list):
def sift_up(self, idx):
v = self[idx]
if self.root() == idx:
return
pidx = self.parent(idx)
pv = self[pidx]
if pv < v:
@giannitedesco
giannitedesco / bfs.py
Last active December 19, 2015 02:38
Little python library to convert between inorder, BFS and vEB tree layouts. The idea is to do this without constructing any trees. That is to say, in a manner appropriate for implicit layouts, eg. for a database.
from collections import deque
class Bfs(int):
def left(self):
if self.height == 0:
raise ValueError
return Bfs(self * 2, height = self.height)
def right(self):
if self.height == 0: