# Shadow Algorithms: Encryption and Compression This document describes each algorithm twice. The first telling is a parable. The second is the same algorithm restated in the technical language of cryptography and information theory. The parable is not a simplification. It is the same structure seen from a different basis. A reader who understands the parable already understands the algorithm; the technical section names the parts precisely so the reader can find them in the literature and in the code. ## Shadow Encryption ### The Parable A king wished to send a secret letter to a distant ally. He wrote his message on tiles, each bearing one of sixty-four hexagrams from the Book of Changes. But before dispatching them he consulted two clocks in his tower: one that chimed every two hundred and fifty-six heartbeats, the other every hundred. The two clocks never agreed on what hour it was, except at rare moments of alignment when both struck midnight together. At each tile's position in the sequence, the king read the disagreement between the clocks and used it to rotate that tile's inner and outer faces independently, the way one might spin the inner and outer rings of a combination lock by different amounts. He then pressed each rotated tile into wet clay on a lattice of crystal grown from his ally's public seal, where the tiles sought out compatible sites and bonded like seeds finding soil. When the lattice hardened he shipped it. His ally, holding the private mold that had shaped the original crystal, could test each bonded site against all sixty-four possible hexagrams to find which one was lodged there, then consult the same pair of clocks to reverse each position's unique rotation and recover the original letter. An eavesdropper, lacking the mold, faces a wall of sixty-four possibilities at every site, tangled into a crystal whose geometry makes the search for the nearest answer impossibly expensive. ### The Technical Description Shadow encryption is a lattice-based public-key cipher that adds a position-dependent permutation layer derived from the drift between two incommensurable clock periods. The plaintext is first converted to a stream of hexagram tokens. Each byte of input maps to a six-bit symbol drawn from the sixty-four hexagrams of the I Ching encoding, where each hexagram is composed of an inner trigram and an outer trigram, each carrying three bits. This encoding is the bridge between the byte-oriented plaintext and the algebraic structure the cipher operates on. At each token position, the cipher evaluates the epoch phase function. An epoch is defined by two coprime periods: a binary period (a power of two) and a decimal period (a power of ten). The phase at position n is the exact rational difference between the binary clock's fractional progress and the decimal clock's fractional progress at step n. Because the two periods are coprime, this phase drifts through a non-repeating sequence of distinct rational values before the clocks realign at the least common multiple. From the phase at each position, the cipher derives two elements of the symmetric group on three objects. One element permutes the inner trigram; the other permutes the outer trigram. These are independent rotations of the two halves of the hexagram. The symmetric group on three elements has six members, so the combined permutation space is thirty-six possible pairs per position. The phase determines which pair is applied. Because the phase is different at every position within a period, each token receives a structurally unique rotation. The permuted tokens are then bonded into a lattice crystallised from the recipient's public key. The lattice is a constraint graph: each node admits elements of a specific type, and elements seek compatible nodes through a random walk. The bonding pattern records which hexagram value occupies each lattice site, hashed against the recipient's basis. Dissolution passes add controlled noise to the bonding pattern, establishing the error term that makes the closest vector problem hard for an adversary. Decryption reverses the process. The private key holder knows the constraint structure that shaped the lattice, making the closest vector problem tractable. For each occupied site, they test all sixty-four hexagram values against the stored hash to identify the bonded token. The token's position in the original stream is recovered from the lattice node's projection metadata. The same epoch phase function regenerates the permutation pair at each position, and the inverse permutations recover the original hexagram. The hexagrams are decoded back to bytes. The security rests on the hardness of the closest vector problem on the constraint lattice. The permutation layer does not add computational security in itself, since the symmetric group is small. What it provides is semantic security: the distribution of encrypted hexagram values is independent of the plaintext distribution, because the position-dependent permutations destroy frequency statistics. An eavesdropper performing frequency analysis on the encrypted token stream learns nothing about the plaintext token frequencies. The epoch binding further prevents ciphertext transplantation: a message encrypted under one epoch cannot be decrypted under a different epoch because the permutation schedule is epoch-specific. ## Shadow Compression ### The Parable A scribe had a long manuscript to send and wanted to make it smaller for the journey. She also had a short private note she wished to tuck inside, hidden from anyone who did not know to look for it. She transcribed the manuscript into the same tiles the king used, each bearing one of sixty-four faces. For each tile in the sequence she listened to the same two clocks in the tower and heard them disagree, as they always did. The disagreement told her where each tile's natural resting position was, the home orientation that anyone with the same pair of clocks would expect it to be in. If she had nothing to hide at that position she left the tile at home. But when she had a piece of her private note to tuck in, she turned the tile away from home to one of thirty-five other orientations, and the amount she turned it by was the hidden message, written in the language of small rotations. She then counted how often each tile face appeared in the rotated manuscript and gave the common faces short names and the rare faces long names, the way a scribe in a hurry invents abbreviations for words she writes often. She packed the abbreviated manuscript into one bundle, and alongside it she packed a record of how far each tile had been turned from home. The abbreviation table and the clock settings she wrote on the outside of the parcel. A reader who received the parcel could rebuild the abbreviation table, expand the short names back to tile faces, consult the same clocks to learn where home was for each position, and read off how far each tile had been turned. The turns, translated back into letters, spelled out the hidden note. The original manuscript, un-turned and un-abbreviated, was the scribe's text exactly as she wrote it. ### The Technical Description Shadow compression combines Huffman coding with a steganographic auxiliary channel carried in the permutation metadata of the encoding. The input data is converted to hexagram tokens using the same six-bit encoding as the encryption algorithm. Each token is then subjected to a position-dependent permutation selected by the epoch phase function, exactly as in shadow encryption. However, in the compression case the choice of permutation pair is not fixed by the phase alone. The phase determines the home pair, the default permutation that carries no auxiliary information. Thirty-five other pairs are available at each position. When auxiliary data is present, the compressor selects a non-home pair whose index encodes up to five bits of auxiliary payload (the base-two logarithm of thirty-five is approximately five point one). After permutation, the compressor builds a frequency table over the permuted token stream. This ordering is critical: because different permutation pairs map the same original token to different output values, the frequency distribution of the permuted stream differs from the original. The Huffman tree must be built from the actual values it will encode. The frequency table uses exact rational weights computed from integer counts divided by the total token count. All weight comparisons during tree construction use rational arithmetic with no floating point operations. This guarantees that the Huffman tree is identical on every platform that reconstructs it from the same frequency table, eliminating the nondeterminism that floating point tie-breaking would introduce. The Huffman tree assigns variable-length prefix-free codes to each of the sixty-four hexagram values, with shorter codes for more frequent values. The permuted token stream is encoded as a bitstream using these codes. This is the primary stream: the compressed representation of the data. Alongside the primary stream, the compressor packs the permutation pair index for each token position into a shadow stream, using six bits per index. This shadow stream records which of the thirty-six possible pairs was used at each position. The home pair is index zero; indices one through thirty-five encode auxiliary data values zero through thirty-four. The wire format bundles the primary stream, the shadow stream, the frequency table, the epoch parameters, the original data length, the token count, the auxiliary payload length, and a content hash into a single binary packet. The frequency table occupies two hundred and fifty-six bytes (sixty-four entries of four bytes each). The content hash is a four-hundred-and-forty-eight-bit digest of the original data, used to verify decompression integrity. Decompression reverses the process. The frequency table is read from the wire format and used to rebuild the identical Huffman tree. The primary bitstream is decoded to recover the permuted token stream. The shadow stream is unpacked to recover the permutation pair index at each position. For each token, the epoch phase determines the home pair, the stored index selects the actual pair used, and the inverse permutations recover the original hexagram. If the index was nonzero, the auxiliary bits encoded by that index are extracted and accumulated. The hexagrams are decoded to bytes, the content hash is verified, and the auxiliary payload is reassembled from the accumulated bits. The shadow channel capacity is approximately five bits per hexagram token. Since each token carries six bits of primary data, the auxiliary bandwidth is roughly eighty-three percent of the primary bandwidth. This exceeds the raw cross-basis capacity of the binary-decimal shadow (approximately three and a third bits per ten decimal digits) because the symmetric group on three elements squared amplifies the channel: thirty-six permutation pairs in a six-bit symbol space is a richer structure than the bare logarithmic residual between two number bases. The compression ratio of the primary stream depends on the entropy of the permuted token distribution. The shadow stream adds a fixed overhead of six bits per token regardless of whether auxiliary data is present. For data with low entropy (highly repetitive content), the Huffman layer compresses the primary stream well, but the shadow overhead remains proportional to the token count. The format is most efficient when the auxiliary channel is actually used, since the shadow stream overhead is then carrying payload rather than recording a stream of zeros.