This is an experiment in using the chaotic motion of three gravitating bodies to encrypt messages. A secret key decides where three bodies start. A physics simulation runs them forward. Their motion is sampled and turned into a stream of bytes, and that stream is combined with a message to encrypt it. The view above lets you watch it happen.

The short version of what I found: it works as a cipher, but the chaos isn't what makes it work. Every property that matters for security turned out to come from the standard cryptographic pieces around the simulation, not from the simulation itself. This page explains how it's built, what I measured, and why the more ambitious idea, getting public-key encryption out of orbits, doesn't hold up.

This is just an experiment, not a secure cipher. Don't use it to protect anything real nor treat it as a method of securely encrypting information.

Using the view

Drag to rotate, hold ⌘ or Ctrl and scroll (or pinch) to zoom, and right-drag to pan. On a phone, use two fingers to rotate and zoom. Reset view brings the camera back. Play runs the orbit forward, and the time slider scrubs through it.

The faint orbit is the public system: three bodies anyone can see. The bright orbit is the keyed system, which is the public one moved by tiny offsets that only the key holder can compute. The keystream comes from the bright one. Spread sets how large those offsets can be.

In the Message section you can encrypt a message and watch the keystream bits fill in as the orbit plays. The bytes your message actually uses are highlighted, which shows how little of the keystream a short message needs.

This page replays systems and keys that were computed ahead of time, because the simulation runs in Python. The full version, where you design your own system and generate your own keys, runs locally from the repository.

The three-body problem

Two bodies orbiting each other follow simple, repeating paths that can be written down exactly. Add a third and, in general, there's no formula. You have to simulate the motion step by step, and many configurations are chaotic: two runs that start with their initial positions even a near imperceptible distance apart end up somewhere completely different.

Two classic configurations show both extremes.

The simulations use REBOUND, an open-source N-body code, with its IAS15 integrator. IAS15 adapts its step size, taking tiny steps through close encounters and larger ones elsewhere, which is what keeps chaotic runs accurate. Units are chosen so the gravitational constant is 1.

Watching chaos

The basic experiment is to run a system twice, once as given and once with one body nudged by a tiny amount, and measure how far apart the two runs get.

The separation between each preset and its nudged twin from t = 0 to 100, on a log scale. The figure eight's rises slowly from 1e-8 to a few times 1e-6. The Pythagorean problem's spikes at each close encounter, climbs steadily from about t = 30 to around 1 by t = 60, then levels off between about 1 and 10.
How far each nudged twin gets from its original run.

A finite-time Lyapunov estimate puts a number on this: the average rate at which nearby runs separate. For the figure eight it decays toward zero (about 0.06 by t = 100). For the Pythagorean problem it stays clearly positive (about 0.3 around the escape, 0.22 by t = 100).

Finite-time Lyapunov estimates from t = 0 to 100. The figure eight's peaks near 1.4 early on and falls steadily to about 0.06. The Pythagorean problem's spikes at its close encounters, rises from about t = 30 to around 0.3 by the escape, then eases to about 0.22.
Finite-time Lyapunov estimates for the two presets.

Shrinking the nudge revealed something more interesting. Nudges of 10−4 and 10−7 track each other three orders of magnitude apart, as they should. But after the deep close pass near t = 16, a 10−13 nudge becomes indistinguishable from a 10−10 one. Below roughly 10−10, the difference between two runs is set by the integrator's own rounding, not by the nudge.

The separation from the unnudged Pythagorean run for nudges of 1e-4, 1e-7, 1e-10 and 1e-13, on a log scale. The 1e-4 and 1e-7 curves keep the same shape three orders of magnitude apart. The 1e-13 curve jumps up at the close pass near t = 16 and from about t = 20 lies on top of the 1e-10 curve.
The Pythagorean problem at four nudge sizes.

That matters later. The lowest digits of a simulated state record arithmetic, not physics.

From motion to bytes

Turning an orbit into a keystream takes five steps.

  1. Warm up. Integrate for 10 time units before taking anything, so the bodies have had time to mix.
  2. Sample. Every 0.1 time units over the window, record the positions and velocities of all three bodies plus the three distances between them: 21 numbers per sample, 501 samples in all.
  3. Quantize. Round each number to fixed point with 40 fractional bits and pack it as a little-endian integer, so it's exactly reproducible.
  4. Extract. Take bytes from each sample in one of two ways:
    • Raw: the low-order bits of each number, taken directly.
    • Hashed: SHA-256 over each packed sample, giving 32 bytes per sample.
  5. Combine. XOR the bytes with the message. Decryption repeats the same steps and XORs again.

Decryption depends on the simulation being exactly repeatable, and it is: the same inputs on the same setup give bit-identical output, run after run. It's also fragile. Changing the integrator's tolerance changes the keystream completely, and changing the times it stops to take samples changes about 90% of it.

The raw extractor is the honest test of whether motion itself produces anything random. The hashed one is what you would actually use. That distinction runs through everything below.

Keys

The first version of the cipher used a 32-byte random seed as the key. SHAKE-256 expands the seed and a per-message nonce into masses, positions and velocities. A candidate system is rejected and redrawn if it's unbound, ejects a body during the window, loses too much energy accuracy, or stalls the integrator. In 3D, about two thirds of candidates are rejected, so a key takes about three attempts.

The app works differently, and closer to the idea I started with: you design the system.

Without the secret you can see the public orbit, but not the keyed one. At the default spread the two start out indistinguishable, and for most systems the bright one visibly pulls away during playback.

The spread can't go below 10−7. Smaller than that, some keyed orbits start the window with values so close to the public run's that the raw extractor's low bits start to follow the public run. From 10−7 up, no measured orbit started that close.

Can orbits do public-key encryption?

This is the part I most wanted to work, and never figured out the first time.

Public-key encryption needs a trapdoor: an operation anyone can perform that's hard to undo, unless you hold a private piece of information. Chaos offers something different. Without the exact starting conditions, nobody can reproduce an orbit, but anyone who has them can do everything: encrypt and decrypt alike. There's no way to hand someone the ability to encrypt without also handing them the ability to decrypt.

The natural attempt borrows the shape of Diffie-Hellman. Everyone starts from a public system. Alice runs it forward for a secret time a and publishes the result, and Bob does the same with a secret time b. Each then runs the other's published state forward by their own time. On paper both end up at time a + b and share a secret. I measured both halves of that.

Top: the gap between Alice's and Bob's final states for each of the 280 exchanges, against a + b, on a log scale. The median grows from about 2e-16 at a + b = 0.5 to about 7e-8 at 60, and the largest gaps reach 1 to 10. Bottom: how many of the 28 exchanges at each total ended on matching 40-bit quantized states, falling from 28 at a + b = 0.5 to 0 at 60.
Alice's and Bob's agreement in the flow exchange, by total time.

So the scheme either fails to agree, or agrees only where the chaos hasn't done anything yet, and an eavesdropper breaks it in both cases. A similar public-key scheme built on Chebyshev polynomials, another chaotic system, was proposed by Kocarev and Tasev in 2003 and broken by Bergamo and colleagues in 2005.

What the app does instead is the approach real systems like TLS use. A standard public-key exchange, X25519, agrees on a shared secret: each message uses a fresh one-time keypair, and the result is hashed with both public keys into a secret key. That secret key then picks the keyed orbit, exactly as above. All of the public-key security comes from X25519. The orbit is where the key's influence becomes visible.

What the evaluation found

Statistical tests are diagnostics, not proof of security, and none of these results suggest the construction is secure.

The share of orbits against the seconds taken to derive one, and against the Lyapunov estimate over the window, for 2D and 3D, both on log scales. 3D derivations are about ten times faster, with a median of 0.084 seconds against 0.83. The 3D Lyapunov estimates sit a little lower, with a median of 0.44 against 0.60, and six 3D orbits fall below the figure eight's 0.10. The 2D curve leaves out the nine orbits whose energy broke.
2D against 3D: time to derive an orbit, and how chaotic it is.

The answer to the question I started with: the chaotic dynamics offer no measurable benefit over conventional approaches. Everything that makes the output look random comes from the hash functions around them, and everything that makes it slow comes from the simulation portion.

Limitations

How I built it

I started in September 2025 with a 2D simulation and a set of notebooks exploring this specific brand of chaos, then built the keystream, the cipher and a command-line tool, and did my best to evaluate all of it. Later I moved the simulation to 3D, added a local API and the web app, and spent the fall of 2026 on the part I'd never solved: keyed systems and the public-key layer.

The stack:

References

During the development of this project, lots of sources were used to research the related topics, foremost of which being: