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 figure eight. Three equal masses chase each other around a single figure-eight path, a solution found numerically by Moore in 1993 and proved to exist by Chenciner and Montgomery in 2000. It's stable. Nudge one body by 10−8 and the two runs drift apart only slowly, roughly in proportion to time.
- The Pythagorean problem. Masses of 3, 4 and 5 start at rest at the corners of a 3-4-5 triangle, a setup Burrau studied in 1913. After a tangle of close encounters, the lightest body is flung out around t = 60, and the other two leave together as a tight binary.
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 figure eight grows from a separation of 10−8 to a few millionths by t = 100, with no exponential stretch.
- The Pythagorean problem spikes at each close encounter, then climbs exponentially from about t = 30 until the escape, after which it levels off.

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).

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.

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.
- Warm up. Integrate for 10 time units before taking anything, so the bodies have had time to mix.
- 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.
- Quantize. Round each number to fixed point with 40 fractional bits and pack it as a little-endian integer, so it's exactly reproducible.
- 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.
- 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.
- The public system is your three bodies. Anyone can see it.
- The secret key chooses a small offset to every position and velocity, within a public spread (10−6 by default). That offset system, the keyed orbit, is what produces the keystream.
- Every message gets a fresh nonce, so every message gets its own keyed orbit.
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.
- Do Alice and Bob agree? Only briefly. Their final states were never bit-identical (0 of 280 exchanges). For short exchanges, with a + b up to 5, the differences were rounding-sized and their quantized states still matched in 100 of 112 cases. By a + b = 60, nothing matched, because chaos had amplified the differences.
- Can an eavesdropper recover the secret? Every time. Running the public system forward and searching for Alice's published state recovered her secret time exactly in all 70 searches, with a median search of 0.069 seconds.

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.
- Statistics. The hashed keystream passes the standard tests, because SHA-256 makes it pass. The raw keystream also passes across a wide range of precisions, but in exactly the range where rounding and real motion look the same, so passing doesn't show the motion is random. In the 2D version, about 5% of accepted orbits were numerically broken, with energy errors as large as 2 × 105, and their raw output failed. Moving to 3D removed them from the samples on its own: the drift and stall checks added at the same time didn't reject a single candidate there.
- Sensitivity. Flipping one bit of a seed changes about half the output bits, but that's SHAKE-256 at work, not the orbit. Nudging the starting conditions directly by the smallest possible amount still changes the output once the warm-up amplifies it, though in 3D a few orbits never diverged at all.
- Reproducibility. Output is identical across repeated runs and fresh processes. Any change to the integrator's settings destroys it. It has never been tested across different machines, and it's tied to REBOUND 5.2.2.
- Cost. In 3D, the keystream is about 1,400 times slower than SHAKE-256 once an orbit is known, and about 7,000 times slower counting the work of finding the orbit. The 2D version was far worse: 2,300 and 58,000 times.
- 2D against 3D. Moving to 3D cut the rejection rate from 88% to 68.5% and the median derivation time from 0.83 to 0.084 seconds, but it also made the orbits less chaotic: the median Lyapunov estimate fell from 0.60 to 0.44.
- Nonce reuse. Encrypting two messages with the same key and nonce means that knowing one reveals the other.

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
- It's an experiment, not a secure cipher.
- There's no integrity protection. Flipping a bit of the ciphertext flips the same bit of the message, and the header isn't authenticated, so some changes to it give garbage while others are absorbed by rounding.
- Reusing a key and nonce leaks the XOR of the two messages, so knowing one reveals the other.
- Output isn't guaranteed to match across machines or REBOUND versions, and has only been tested on one machine.
- The raw extractor's low bits are numerical error, not physics.
- Deriving an orbit costs real computation, and a crafted ciphertext can take around 13 minutes to fail.
- Messages are limited by the keystream's length.
- In the app, keys exist only in the open page and are lost on reload.
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:
- Simulation and analysis: Python, REBOUND, NumPy, Matplotlib, Jupyter
- Local API: FastAPI
- Web app: TypeScript, Three.js, Vite
- Cryptography: the
cryptographypackage for X25519, and Python's hashlib for SHA-256 and SHAKE-256
References
During the development of this project, lots of sources were used to research the related topics, foremost of which being:
- H. Rein and S.-F. Liu, "REBOUND: an open-source multi-purpose N-body code for collisional dynamics," Astronomy & Astrophysics 537, A128 (2012).
- H. Rein and D. S. Spiegel, "IAS15: a fast, adaptive, high-order integrator for gravitational dynamics, accurate to machine precision over a billion orbits," MNRAS 446, 1424 (2015).
- C. Moore, "Braids in classical dynamics," Physical Review Letters 70, 3675 (1993).
- A. Chenciner and R. Montgomery, "A remarkable periodic solution of the three-body problem in the case of equal masses," Annals of Mathematics 152, 881 (2000).
- C. Burrau, "Numerische Berechnung eines Spezialfalles des Dreikörperproblems," Astronomische Nachrichten 195, 113 (1913).
- L. Kocarev and Z. Tasev, "Public-key encryption based on Chebyshev maps," ISCAS 2003.
- P. Bergamo, P. D'Arco, A. De Santis and L. Kocarev, "Security of public-key cryptosystems based on Chebyshev polynomials," IEEE Transactions on Circuits and Systems I 52(7) (2005).
- A. Langley, M. Hamburg and S. Turner, "Elliptic Curves for Security," RFC 7748 (2016).