Code
I maintain some computer code for computations relating to my research. These scripts are mostly for the computer algebra systems Pari/GP and Sage. You are welcome to download and use these scripts; they and the software to run them (Pari & Sage) are free. Please let me know if you encounter errors.
Notes on usage
- To use a Pari/GP script, load the script by typing “\r filename” at the prompt, where filename includes the path, then see the script for descriptions of functions;
- To use a Sage script, type “attach(‘filename’)” at the prompt; it also works simply to cut and paste the text of the script file into the first cell of a notebook;
- To use a Sage notebook, upload it to the notebook interface.
Illustrating Number Theory
I’ve taken an interest in the illustration of number theory with computers and 3d printing, etc. Click here to view my gallery.
SIDH
Isogeny-based cryptography is a primary candidate for post-quantum cryptography.
- Attacking SIDH variants [ github ] – This code demonstrates the attacks in our paper, Improved torsion point attacks on SIDH variants with Victoria de Quehen, Péter Kutas, Chris Leonardi, Chloe Martindale, Lorenz Panny, and Christophe Petit.
Ring Learning with Errors
Ring Learning with Errors is a front-runner for a hard problem upon which to base post-quantum cryptography. Here are some algorithms for attempting to solve it.
- Ring-BKW [ Code etc. ] – This code supports my paper Algebraic aspects of solving Ring-LWE, including ring-based improvements in the Blum-Kalai-Wasserman algorithm.
- Ring-LWE and Poly-LWE attack [ Sage Notebook ] – This implements the algorithms in our paper Provably weak instances of Ring-LWE (with Yara Elias, Kristin E. Lauter and Ekin Ozman).
Modular Arithmetic
- Tate Pairing Visualizer [ Interactive Web App ] – The reduced Tate pairing t : E[n] × E(F_p)/nE(F_p) → μ_n on small curves with full rational n-torsion, coloured by the n-th roots of unity themselves. For a chosen P ∈ E[n], the character Q ↦ t(P, Q) is a plane wave on the torus E(F_p) ≅ Z/d₁ × Z/d₂ and looks like noise on the points (x, y); a second tab colours E[n] by the self-pairing t(P, P), a quadratic form whose level sets are discrete conics, next to the alternating Weil pairing, whose self-pairing is flat. Every value comes from Miller’s algorithm.
- Gross / Lattice [ Interactive Web App ] – The definite-quaternion sibling of Minkowski / Lattice and Farey / Lattice: the Gross lattice (ℤ + 2R) ∩ B⁰ of the maximal order R = ℤ⟨1, I, (1+J)/2, (I+K)/2⟩ of B_{p,∞} (p ≡ 3 mod 4), seen on the sphere of trace-zero directions. Every primitive lattice vector is an optimal embedding of the imaginary-quadratic order of discriminant Δ = −d into R, drawn as its two antipodal poles and its polar great circle, coloured and faded by norm d with the same norm strip. Click two embeddings for the exact pair data: δ = d₁d₂ − t², the index k = δ/4p of the order they generate, the crossing angle, and the intersection axis of the two circles as a lattice vector with its own order and field; incidence of poles and circles is tested exactly.
- Farey / Lattice [ Interactive Web App ] – The O(2,1) companion to Minkowski / Lattice: every integer binary quadratic form (a, b, c) of norm D = b² − 4ac is a geodesic of the hyperbolic plane, drawn in the Poincaré disk or the upper half-plane and enumerated to pixel depth for the current view. Norm 1 is the Farey tessellation, norm 4 the tessellation by fundamental domains of SL₂(ℤ), norm d² the geodesics between rationals of determinant d; a norm strip fades the tessellations in and out, or shows them all overlapping, coloured by norm. A class mode colours one norm by ideal class (SL₂(ℤ)-orbits of closed geodesics, narrow classes computed by Gauss reduction and composition, checked against PARI) or, for square norms, by the index-d sublattice of ℤ² spanned by the endpoints, with the class numbers of the real quadratic fields displayed.
- Farey Hyperboloid [ Interactive Web App ] – A demo companion to the O(2,1) Explorer: the one-sheeted hyperboloid b² − 4ac = 1 is doubly ruled and its integer points are the edges of the Farey tessellation. Slide a point along a ruling and watch its geodesic in the upper half-plane pivot about one endpoint, junction to junction.
- Lattice Descent [ Interactive Web App ] – A sphere at every point of the integer lattice ℤ². The eye descends onto the origin and turns: from there only the primitive points (x, y), with gcd(x, y) = 1, can be seen, one in each rational direction y/x, every other point hidden exactly behind one of them. The rationals, as a lattice.
- Quadratic Starscapes: Lattices and Lorentz Geometry [ Interactive Web App ] – A workbench for the coefficient lattice of binary quadratic forms: a tracked sample of ℤ³ inside the discriminant cone b² − 4ac = 0 (drawn round in the coordinates (a − c, b, a + c)), linked to the upper half-plane of roots. Three operations with separate controls make the distinction visible: Lorentz motions ρ(g), g ∈ SL(2,ℝ), move every point and root (by the Möbius map) while fixing all discriminants and the Gram matrix; an integral change of basis B ← BU moves nothing physical, only the basis arrows, the coordinate labels and J_B ← UᵀJ_BU; and the same U applied actively, B ← UB, moves the vectors themselves and changes discriminants and root types. Slider previews from a captured state with apply, undo and reset, exact SL(3,ℤ) matrices, and four presets: a Möbius motion, a new basis for the same picture, a shear crossing the cone, and which operations commute.
- O(2,1) Explorer [ Interactive Web App ] – Integer binary quadratic forms as vectors (a, b, c) of a three-dimensional Minkowski lattice with q = b² − 4ac, linked to the upper half-plane: each vector’s orthogonal plane cuts the light cone and the hyperboloid model, giving the geodesic, interior point or boundary point of the form. Norm-level surfaces, exact pairing queries, the modular-group action with undo, and shared links.
- Minkowski / Lattice [ Interactive Web App ] – A four-dimensional lattice seen through the circles of its vectors: each vector (a, τ) cuts the sphere in the circle a·x = τ, coloured and faded by its Minkowski norm. Deform the lattice continuously (stretches, shears, cone tilts, Lorentz boosts) and watch the circles move through the stereographic plane and the sphere; a norm strip isolates any shell.
- Rational Lines in RP² [ Interactive Web App ] – The SL(3,Z)-orbit of a projective line, drawn in an affine chart: every rational line ax + by + c = 0 up to a height cutoff, faded by arithmetic complexity, or the word ball under the elementary generators; three charts, a dual-plane view, line selection and a generator tool.
- Möbius Transformation [ Interactive Web App ] – A Möbius transformation of the complex plane as a full-screen domain colouring: hue is the argument of f(z), lightness its modulus, and the integer grid of the target plane is pulled back to circles through the pole. The map is set by the images of 0, 1 and ∞, three dots you drag or nudge with the arrow keys while the colouring morphs; the formula, conjugacy type (elliptic, parabolic, hyperbolic, loxodromic) and fixed points update live.
- Möbius Graphs [ Interactive Web App ] – The graph of a real Möbius transformation x ↦ (ax+b)/(cx+d) drawn on the torus RP¹ × RP¹ unfolded to a square, or all of SL(2,Z) with entries bounded by N at once; hover to identify each curve.
- Neural n-gram Explorer [ Interactive Web App ] – A tiny neural language model made completely inspectable: a bigram or trigram over Tiny Shakespeare with a shared two-dimensional embedding and one to three tanh layers. Follow a prediction through the network, edit any of its few hundred parameters, step through one real training example (forward, loss, backward, apply), train in the browser, and compare the complete conditional-probability table with the corpus’s empirical frequencies. Companion to Example 4.7 of the LLM course.
- Neural Function Playground [ Interactive Web App ] – Hand-wire a small neural network on two inputs: drag wires to set weights and neuron tiles to set biases, and watch every neuron’s function of (x₁, x₂) and the output heatmap respond immediately. No training; exercises (half-plane, diamond, XOR, three-class sectors) with loadable example constructions, per-layer activations including a softmax output over several classes, explicit colour scales, and shareable links.
- Index Calculus Explorer [ Interactive Web App ] – The index calculus algorithm for discrete logarithms as a picture: every residue g^x mod p is a bar of length ln(g^x mod p) around a circle, positioned by its exponent; smooth residues split into coloured prime pieces, each giving one linear relation modulo p − 1. An exact solver (prime-power elimination plus the Chinese remainder theorem) recovers the factor-base logarithms, a search mode collects the relations one trial at a time, and a final stage finds any target logarithm.
- Modular Arithmetic Playground [ Interactive Web App ] – The dynamics of x ↦ ax, x ↦ x + a, x ↦ x^a and x ↦ a^x on the integers mod n, drawn as cycles and trees or as string-art chords of a circle, morphing between the two. Handles moduli into the tens of thousands.
- Elliptic Curve Playground [ Interactive Web App ] – The dynamics of P ↦ aP and P ↦ P + Q on the points of y² = x³ + Ax + B mod n, drawn as cycles and trees or as the points in the plane mod n, morphing between the two. For composite n the chord–tangent formulas can fail; failing points flow into a sink labelled by the factor of n they reveal (Lenstra’s method in miniature).
Schmidt Arrangements
- Schmidt Arrangement Visualizer [ Interactive Web App ] – Explore the Schmidt arrangement of any imaginary quadratic field directly in the browser: progressive generation, exact circle data with verified Bianchi matrices, Gaussian Apollonian swaps, curvature and prime highlighting, and colouring tools.
- Schmidt Orbits [ Interactive Web App ] – Choose three -rational points on the Gaussian Schmidt arrangement; the circle through them and its entire -orbit are computed exactly and drawn in a contrasting colour over the arrangement.
- Apollonian-like packings and Schmidt Arrangements [ Sage Notebook | Interactive Web Page ] – This draws pictures of Schmidt Arrangements and K-Apollonian circle packings as described in my papers Visualizing the arithmetic of imaginary quadratic fields and The Apollonian structure of Bianchi groups.
- My graduate student, Daniel Martin, has some remarkable code for Schmidt arrangements and his own generalizations.
Elliptic Divisibility Sequences and Elliptic Nets
- Elliptic Net Visualizer [ Interactive Web App ] – The rank-two elliptic net W(m, n) of a curve and two points over a finite field Fq as a grid of colours, with the values on hover: coloured by value mod p, by discrete logarithm to a chosen generator, or (over Fpk) by coordinates or norm. Shows one full true period of the net, the zero lattice, and the quasi-periodicity multipliers W(v + λ) = W(v)·c·ambn.
- Tate pairing computation via elliptic nets [ Pari/GP ] – This implements the algorithms in my paper The Tate pairing via elliptic nets. Note: For other implementations, see also Graeme Taylor, who has implemented it for SAGE and has notes on his improvements; Ben Lynn, who has implemented it in his Pairing-Based Cryptography Library as part of his thesis; and and Augusto Jun Devegili at University College Dublin. Many of the formulas my be found in my formulary.
- Elliptic Divisibility Sequences Tools [ Pari/GP | SAGE | Example Sage Notebook | PDF of Example Notebook ] – These are general-purpose algorithms for experimenting with elliptic divisibility sequences over any field. Move between sequences and curves, generate terms efficiently, etc. Many of the formulas may be found in my formulary.
- Elliptic Nets Tools [ Pari/GP ] – These are general-purpose algorithms for experimenting with rank two elliptic nets over any field. It requires the use of the Elliptic Divisibility Sequences Tools above. Many of the formulas may be found in my formulary.
Ethiopian Dinner Game
- Ethiopian Dinner Game [ view SAGE notebook online | SAGE script | SAGE notebook for download ] – Tools for experimenting with the Ethiopian Dinner Game. See the paper How to make the most of a shared meal: plan the last bite first.
Sage Mathematics Software
I do a wee little bit of development for the mathematical software Sage.
- Sage Mathematics Software
- Single cell Sage computation online (example 2+2 or EllipticCurve(’37a’).ap(79))
- Some example code for plotting (if you want to use the single cell above as a graphing tool)
- Look for me on trac (sage development)
- My group at Sage Days 33
- Sage Developer’s Guide
Support and Disclaimer
Some of this material is based upon work supported by the National Science Foundation, the National Security Agency, and the National Science and Engineering Research Council. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation of the USA (NSF), the National Security Agency (NSA), or the National Science and Engineering Research Council of Canada (NSERC).