Skip to content

Instantly share code, notes, and snippets.

@PM2Ring
PM2Ring / aes_ecb.py
Last active January 16, 2018 13:51
Call the AES_set_encrypt_key, AES_set_decrypt_key, and AES_ecb_encrypt functions from the OpenSSL library using ctypes
#!/usr/bin/env python3
''' AES ECB
Call the AES_set_encrypt_key, AES_set_decrypt_key, and
AES_ecb_encrypt functions from the OpenSSL library
Uses info from /usr/include/openssl/aes.h
Also see https://boringssl.googlesource.com/boringssl/+/2490/include/openssl/aes.h
@PM2Ring
PM2Ring / sha1_demo.py
Created October 4, 2017 16:36
An implementation of SHA-1 in pure Python 3
#!/usr/bin/env python3
''' sha1_demo
An implementation of SHA-1 in pure Python 3
Built from the pseudocode at
https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode
Written by PM 2Ring 2017.10.01
@PM2Ring
PM2Ring / bloom_filter_test.py
Created October 2, 2017 17:13
Bloom filter demo
#!/usr/bin/env python3
''' Testing a Bloom filter implementation
See https://en.wikipedia.org/wiki/Bloom_filter
Written by PM 2Ring 2017.09.29
'''
from random import seed, randrange
@PM2Ring
PM2Ring / tk_iso_ellipse0.py
Created October 2, 2017 12:27
Fitting an ellipse into an isoceles triangle
#! /usr/bin/env python3
''' iso_ellipse. An ellipse that touches an isoceles triangle at the
midpoint of its base and at a given distance on the sides.
The apex of the triangle is at the origin, with the triangle's axis
on the +X axis. The slopes of the equal sides are m and -m,
the "height" is V, so the other 2 vertices are at (V, mV) and (V, -mV).
We want an ellipse that's tangential to the triangle at (X, Y) and (X, -Y)
@PM2Ring
PM2Ring / fano_plane.svg
Created October 2, 2017 12:19
The usual projection of the Fano plane. Hover over a node to see the nodes on the line dual to that node.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / fano_disc2.svg
Created October 2, 2017 11:33
The Fano plane as a disc
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / algorithmx_spotit.py
Created September 27, 2017 11:12
SpotIt Stuff
#!/usr/bin/env python3
''' algorithmx_spotit
Generate small Spot-It decks by brute force searching for
the exact cover of pairs of cards which share a symbol.
Uses Knuth's Algorithm X for the exact cover problem.
The Algorithm X code, using dicts instead of doubly-linked
circular lists was written by Ali Assaf.
@PM2Ring
PM2Ring / case_insensitive_string.py
Created July 23, 2017 12:52
Case-insensitive string class
#!/usr/bin/env python3
''' Case-insensitive string class
A string class that uses lower-case hashing and comparisons.
It also uses case-insensitive comparison when compared with
normal `str` strings.
CIStr defines all 6 rich comparison methods, although only
the `__eq__` method is needed for dictionary and set use.
@PM2Ring
PM2Ring / tk_viewer_simple.py
Created July 18, 2017 20:05
A Tkinter viewer for named PIL Images
#!/usr/bin/env python3
''' A Tkinter viewer for named PIL Images
Image windows can be iconified / deiconified individually via buttons
in the main viewer window, or iconified / deiconified en masse by
iconifying / deiconifying the main viewer window.
Written by PM 2Ring 2017.07.16
'''
@PM2Ring
PM2Ring / PIL_bitmap_bug.py
Created July 14, 2017 17:30
Demonstrate the PIL .fromarray bitmap bug
#! /usr/bin/env python3
''' Demonstrate the PIL .fromarray bitmap bug
PIL's Image.fromarray function has a bug with mode '1' images
See
https://stackoverflow.com/questions/2761645/error-converting-pil-bw-images-to-numpy-arrays
Written by PM 2Ring 2017.06.26