This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Format preserving encryption using a Feistel network | |
See https://stackoverflow.com/a/51429458/4014959 | |
Written by PM 2Ring 2016.08.22 | |
Version using Blake2 hashing 2021.06.14 | |
Added pair permutation 2024.01.17 | |
""" | |
from hashlib import blake2s as blake | |
from random import Random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Plot filled ellipse in 3D. | |
With major axis and line of nodes | |
Written by PM 2Ring 2023.9.24 | |
""" | |
var('th') | |
deg = n(pi / 180) | |
def ellipse(a, ec): |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Gauss / Salamin / Brent true AGM pi | |
Binary fixed point | |
Written by PM 2Ring 2023.11.1 | |
""" | |
from math import isqrt | |
def AGM_pi(loops, bits): | |
a, b = 1 << bits, isqrt(1 << 2*bits-1) | |
s = 1 << bits-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Chromostereopsis illusion | |
With generated blue noise dither (void & cluster), | |
Poisson disk, white noise, checks, and undithered. | |
See https://mathematica.stackexchange.com/q/289992 | |
""" | |
import numpy as np | |
from scipy import ndimage | |
from sage.repl.image import Image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" BBerg32 | |
Primality test for 32 bit integers using a single SPRP test. | |
The SPRP base comes from a hash table. | |
Hash and bases by Bradley Berg | |
See https://techneon.com/download/is.prime.32.base.data | |
""" | |
bases = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(0, 1) : 50 | |
(1, 0) : 50 | |
(0, 2) : 258 | |
(1, 1) : 600 | |
(2, 0) : 258 | |
(0, 3) : 186 | |
(1, 2) : 1086 | |
(2, 1) : 1086 | |
(3, 0) : 186 | |
(0, 4) : 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Maxwell–Boltzmann distribution | |
See https://en.m.wikipedia.org/wiki/Maxwell%E2%80%93Boltzmann_distribution | |
Written by PM 2Ring 2021.06.20 | |
""" | |
# Gas constant g⋅m^2⋅s^−2⋅K^−1⋅mol^−1 | |
R = 8314.46261815324 | |
@interact | |
def _(T=('temp (°C)', 20), mass=('mass (g/mol)', 29), | |
auto_update=False): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Lorenz attractor | |
From https://en.wikipedia.org/wiki/Lorenz_system | |
Modified for Sagemath by PM 2Ring 2023.01.04 | |
""" | |
import numpy as np | |
from scipy.integrate import odeint | |
# Build Bezier curves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Borwein + Borwein quadratic pi | |
Algorithm 2.1 from "Pi and the AGM" (Wiley, 1987) | |
Written by PM 2Ring 2023.1.2 | |
""" | |
from math import floor, log, pi | |
from decimal import Decimal as D, getcontext | |
def borwein_pi(loops): | |
x = D(2).sqrt() |
NewerOlder