The Trifid cipher begins with an unusual proposition: instead of replacing a letter with another letter, break the letter into three pieces, mix those pieces with pieces from other letters, and only then turn the result back into readable characters.
Its alphabet is not written in a line. It sits inside a cube. That cube has three layers. Each layer contains three rows, and each row contains three columns. There are therefore 27 possible positions: enough for the 26 letters of the English alphabet and one extra symbol. A letter is identified by its position in the cube. It might be at layer 1, row 3, column 1, giving the coordinates 131. Another might occupy 223 or 312. These three digits become the raw material of encryption.
Trifid does not simply turn each letter into a three-digit number and leave it there. It takes the coordinates from several letters, separates their first, second and third digits, and recombines them into entirely new triplets. Those new triplets point to other letters in the cube. In other words, the cipher dismantles letters, rearranges their internal coordinates, and rebuilds them as ciphertext.
This distinguishes Trifid from simple substitution systems such as Caesar or Atbash. In Atbash, an A always becomes Z. In Trifid, the encrypted form of a plaintext letter depends on the other letters in its block. Repeating the same plaintext letter does not necessarily repeat the same ciphertext letter.
The cipher was devised by French cryptographer Félix Delastelle around the turn of the twentieth century and described in his Traité élémentaire de cryptographie, published in 1902. It developed the fractionation principle used in his earlier Bifid cipher, but added a third dimension. Trifid is still not secure by modern standards, but it moves beyond simple alphabet substitution by dividing letters into smaller components that carry information across neighbouring letters.
Trifid at a Glance
| Feature | Trifid Cipher |
|---|---|
| Cipher type | Fractionating substitution and transposition cipher |
| Inventor | Félix Delastelle, France |
| Historical publication | Traité élémentaire de cryptographie (1902) |
| Alphabet | 26 letters plus a 27th symbol |
| Key structure | A 3×3×3 cube arrangement and a fractionation period |
| Letter representation | Three coordinates: layer, row, column |
| Main process | Separate coordinates by row, then regroup into new triplets |
| Typical period | Five or another suitable block length; the period must match for decryption |
| Example | AIDE-TOI, LE CIEL T'AIDERA → FMJFV OISSU FTFPU FEQQC |
| Decryption | Reverse the coordinate rearrangement |
| Security | Breakable classical cipher; educational rather than secure |
| Best use | Cryptography study, puzzle design, historical demonstrations and programming |
Trifid teaches several important principles together: keyed alphabets, three-dimensional coordinates, fractionation, transposition, reversibility, diffusion and the limitations of hand ciphers. Where a Caesar cipher moves letters, Trifid takes them apart.
Why the Alphabet Lives in a Cube
A standard English alphabet has 26 letters, but a square with five rows and five columns has only 25 positions ($5\times5=25$). This is why classical 5×5 Polybius squares and many Playfair and Bifid implementations combine I and J, or otherwise adapt the alphabet. Trifid instead uses three possible values for each of three coordinates, giving $3\times3\times3=27$ distinct triplets, from 111 to 333. Every letter has its own position, with one cell left for a punctuation mark or another agreed symbol.
For the CipherRegister Trifid tool, that extra symbol is a dot (.). Delastelle's commonly reproduced historical example uses a plus sign (+) instead. Both conventions work, provided sender and recipient agree. A dot and a plus sign are not automatically interchangeable inside an actual message, however: they occupy the same logical extra cell only if the corresponding cube alphabets are configured to do so.
The digits in a Trifid coordinate are three labels: the first identifies the layer, the second the row, and the third the column, each taking a value of 1, 2 or 3. The coordinate 231 therefore means layer 2, row 3, column 1; it is not the decimal number two hundred and thirty-one. Encryption depends on separating these three components, rather than treating their combined appearance as an ordinary integer.
Building the Trifid Cube
The simplest possible cube uses the alphabet in ordinary order, with the dot as the final character: ABCDEFGHIJKLMNOPQRSTUVWXYZ. Fill the first layer from left to right and row by row, then continue through the second and third layers. The resulting arrangement gives every symbol a distinct layer, row and column, as shown below.
Layer 1
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | A |
B |
C |
| Row 2 | D |
E |
F |
| Row 3 | G |
H |
I |
Layer 2
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | J |
K |
L |
| Row 2 | M |
N |
O |
| Row 3 | P |
Q |
R |
Layer 3
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | S |
T |
U |
| Row 2 | V |
W |
X |
| Row 3 | Y |
Z |
. |
In this arrangement:
| Letter | Coordinate | Reason |
|---|---|---|
A |
111 |
Layer 1, row 1, column 1 |
H |
132 |
Layer 1, row 3, column 2 |
N |
222 |
Layer 2, row 2, column 2 |
T |
312 |
Layer 3, row 1, column 2 |
. |
333 |
Layer 3, row 3, column 3 |
This plain alphabetical cube is an excellent place to learn. It is not a sensible secret key, because anyone who recognises the arrangement already knows the mapping. A proper keyed example rearranges the cube. One traditional way to do that is to take a keyword, remove repeated letters while keeping their first appearances, then append the unused letters in alphabetical order.
For the historical keyword FELIX MARIE DELASTELLE, the distinct letters in order are FELIXMARDST. Append the unused letters alphabetically, followed by the extra symbol, to produce the complete cube alphabet: FELIXMARDSTBCGHJKNOPQUVWYZ. Filling the layers in the same order as before produces this keyed arrangement:
Layer 1
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | F |
E |
L |
| Row 2 | I |
X |
M |
| Row 3 | A |
R |
D |
Layer 2
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | S |
T |
B |
| Row 2 | C |
G |
H |
| Row 3 | J |
K |
N |
Layer 3
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | O |
P |
Q |
| Row 2 | U |
V |
W |
| Row 3 | Y |
Z |
. |
This is the cube used in the worked example below. Delastelle's printed convention places + where this tool places .; the letters and their coordinates are otherwise the same. Notice how the keyword changes the positions. A is now 131, E is 112, and T is 212. The message cannot be decrypted correctly unless the recipient knows the same cube arrangement and the same period.
The Heart of Trifid: Fractionation
Fractionation simply means breaking something into smaller parts. In Trifid, each letter breaks into three coordinates. A block of five plaintext letters therefore becomes fifteen coordinate digits. The cipher performs three operations:
- Substitute letters with coordinates. Look up each plaintext letter in the cube.
- Transpose the components. Write all the layer digits together, then all the row digits, then all the column digits.
- Recombine and substitute. Read the rearranged digit stream in threes and look up each new triplet in the cube.
The important subtlety is that a new three-digit group may borrow its digits from different plaintext letters. For instance, the first ciphertext character of a five-letter block may be constructed from the layer coordinates of the first three plaintext characters. The next ciphertext character can contain a mixture of layer digits and row digits. This is why Trifid does more than relabel the alphabet. It changes which parts of the input belong together. A fixed substitution disguises symbols. Trifid also disguises some of their relationships.
A Worked Example: Delastelle's Own Message
Delastelle's classic example uses the French saying AIDE-TOI, LE CIEL T'AIDERA, approximately Help yourself, and heaven will help you. Removing the spaces, hyphen, comma and apostrophe gives the letter stream AIDETOILECIELTAIDERA. Set the fractionation period to 5, so the message is processed in four blocks: AIDET OILEC IELTA IDERA.
Use the keyed cube alphabet FELIXMARDSTBCGHJKNOPQUVWYZ., constructed above from Delastelle's name. The same cube is used both to find the original coordinates and to interpret the rearranged triplets. We can now work through the first five-letter block in full.
Step 1: Look Up the Coordinates
Start with the first block, AIDET, and look up each letter in the keyed cube. Writing its three components in separate rows gives the following coordinate table:
| Plaintext | A |
I |
D |
E |
T |
|---|---|---|---|---|---|
| Layer | 1 |
1 |
1 |
1 |
2 |
| Row | 3 |
2 |
3 |
1 |
1 |
| Column | 1 |
1 |
3 |
2 |
2 |
| Complete coordinate | 131 |
121 |
133 |
112 |
212 |
At this stage, nothing has been mixed. We have simply represented five letters as fifteen digits.
Step 2: Read the Coordinate Rows
Instead of reading each triplet down its column, read all the layer digits from left to right, then all the row digits, then all the column digits:
Layer: 1 1 1 1 2 → 11112
Row: 3 2 3 1 1 → 32311
Column: 1 1 3 2 2 → 11322
Joining the rows produces the continuous stream 111123231111322. No digit has been added or removed; only their order has changed.
Step 3: Rebuild New Triplets
Divide the fifteen-digit stream into new groups of three: 111 | 123 | 231 | 111 | 322. Each triplet is now an address to look up in the same cube, producing these ciphertext letters:
| New triplet | 111 |
123 |
231 |
111 |
322 |
|---|---|---|---|---|---|
| Ciphertext letter | F |
M |
J |
F |
V |
The first plaintext block therefore encrypts as AIDET → FMJFV. There are still five output characters, but the relationship is no longer one plaintext letter to one fixed ciphertext letter: each new position is determined by the rearranged coordinate components.
Step 4: Repeat for Each Block
Perform the same operation independently on the remaining groups.
| Plaintext block | Ciphertext block |
|---|---|
AIDET |
FMJFV |
OILEC |
OISSU |
IELTA |
FTFPU |
IDERA |
FEQQC |
Combining the four blocks gives the complete ciphertext, FMJFV OISSU FTFPU FEQQC. This is the familiar historical example available through Load example in the CipherRegister tool. The dot-versus-plus convention makes no difference to this result because neither special symbol appears in the plaintext or ciphertext.
How Trifid Decryption Works
Decryption reverses the coordinate rearrangement rather than applying the encryption transformation again. Take the first ciphertext block, FMJFV, and look up its five letters in the same keyed cube:
| Ciphertext | F |
M |
J |
F |
V |
|---|---|---|---|---|---|
| Coordinates | 111 |
123 |
231 |
111 |
322 |
Concatenate the coordinates to recover the digit stream 111123231111322. Because the block contains five letters, split those fifteen digits into three runs of five:
Layer digits: 11112
Row digits: 32311
Column digits: 11322
Now read one digit from each run to reconstruct the original triplets:
| Position | Layer | Row | Column | Recovered triplet | Plaintext |
|---|---|---|---|---|---|
1 |
1 |
3 |
1 |
131 |
A |
2 |
1 |
2 |
1 |
121 |
I |
3 |
1 |
3 |
3 |
133 |
D |
4 |
1 |
1 |
2 |
112 |
E |
5 |
2 |
1 |
2 |
212 |
T |
The original block is restored as FMJFV → AIDET. Handle the remaining ciphertext blocks in the same way, using the same fractionation period. The operations undo one another because encryption reorganises coordinates by rows, while decryption reconstructs them by columns.
An incorrect cube or period generally produces gibberish, and neither can be established with certainty merely by reading the ciphertext. Successful decryption depends on knowing both settings and reversing the rearrangement for the actual length of each block.
Why the Period Matters
Trifid has a second important setting besides the cube: the fractionation period. The period is the number of characters whose coordinates are mixed together in one block. With a period of five, each block contributes fifteen digits. With a period of seven, a full block contributes twenty-one digits. Changing the period changes the way the coordinates are regrouped, so it normally changes the ciphertext even when the plaintext and cube stay the same. For example, a 20-letter message encrypted in periods of five consists of four independent five-letter operations. A period of seven would instead produce blocks of seven, seven and six letters. This matters for both diffusion and practical error handling.
A short period is manageable by hand, but limits mixing to a small neighbourhood. Every block is independent. Information never diffuses from one block into another. A longer period mixes coordinate components across more letters, potentially hiding more local relationships, but makes the manual process less convenient.
A period of one is a special failure: no components from different letters can mix at all. Every three-digit coordinate is read back exactly as it started. Encryption returns the original letters unchanged.
Traditional discussions commonly prefer periods coprime to three—for instance, five or seven—because their grouping avoids certain alignments associated with multiples of three. This is a useful design principle for the historical system, not a guarantee of security.
The CipherRegister tool also offers period 0 as a convenient software convention meaning “treat the whole message as one block”. That is not an additional mathematical period of zero letters. It is a shorthand for full-message fractionation.
If you encrypt a message with one period and decrypt with another, you should not expect to recover the original text. The period is part of the key configuration, not a visual formatting preference.
The Mathematics Behind Trifid
Trifid's mathematics is less intimidating than its three-dimensional appearance suggests. There are 27 cells, numbered from zero to twenty-six in the internal ordering of a cube. Suppose n is a cell's zero-based index. Its one-based coordinates are:
$$ \begin{aligned} L &= \left\lfloor \frac{n}{9} \right\rfloor+1,\\ R &= \left\lfloor \frac{n\bmod 9}{3} \right\rfloor+1,\\ C &= (n\bmod 3)+1. \end{aligned} $$
Here, $L$ means layer, $R$ row, and $C$ column. The symbol $\lfloor\cdot\rfloor$ means “round down”. You can reverse the calculation:
$$ n=9(L-1)+3(R-1)+(C-1). $$
For example, the coordinate 231 gives:
$$ n=9(2-1)+3(3-1)+(1-1)=15. $$
So it is the character at zero-based position 15 in the keyed alphabet. In the historical keyed cube, that position contains J. The fractionation itself is a permutation of coordinates: the cipher rearranges the positions of the component digits without changing the digits themselves.
Suppose a block has $m$ letters. Each letter contributes three components, so the block contains exactly $3m$ component digits. Encryption takes the triplets in their original order, writes their first components together, then their second components, then their third components, and regroups the resulting sequence into triplets. This procedure is invertible because the total number of digits stays the same and the receiver knows $m$.
Mathematically, it is helpful to separate two distinct ideas:
- The cube changes the meaning of each triple of digits: which letter corresponds to 111, 112, 113 and so on.
- The period-controlled permutation changes the grouping of those digits: which three components are interpreted together.
Trifid combines these operations. Neither one alone describes the full cipher. It is tempting to quote the number of possible cube arrangements, $27!$, and conclude that Trifid must therefore be enormously secure. But a large theoretical number of arrangements is not the same as resistance to cryptanalysis. Keyword-based cubes occupy only a highly structured subset of those possibilities, and the underlying fractionation has exploitable regularities. For a classical cipher, the real question is not merely how many keys might exist. It is how much the ciphertext reveals about the plaintext and the key.
Félix Delastelle and the Birth of Trifid
Trifid was developed by Félix-Marie Delastelle (1840–1902), a French cryptographer associated with several inventive systems of manual encryption. Delastelle was interested in more than swapping one letter for another. His work explored how letters could be represented in smaller numerical or symbolic components, then recombined in ways that interfered with ordinary language patterns. His Bifid cipher applied this idea to two components, traditionally represented using a square. Trifid extended the concept to three components in a cube.
His work appeared in a period when cryptographers were seeking stronger practical pencil-and-paper systems without relying on machinery. Alphabetic substitution was familiar. Transposition was familiar. Combining the two offered a more ambitious approach. Delastelle's Traité élémentaire de cryptographie was published in 1902, the year of his death. The Trifid system is described there, and its well-known French example illustrates the process of recombining coordinate fragments.
There is an important historical qualification: invention, publication and widespread adoption are different things. A cipher described in a respected historical work was not necessarily used routinely by armies or governments. Trifid is better documented as an ingenious classical system than as a standard operational cipher. Educational accounts note that its practical use was comparatively limited.
This does not diminish its significance. The system demonstrates an important turn in thinking: the unit manipulated by an enciphering process need not be a whole letter. It can be a part of the representation of a letter. That is why Trifid belongs in the history of fractionating ciphers, even though it is obsolete as a security mechanism.
What Makes Trifid Stronger Than Simple Substitution?
Consider a monoalphabetic cipher in which plaintext E always becomes ciphertext Q. Every E becomes Q, irrespective of context. In a long message, the letter-frequency pattern of the language survives, merely relabelled. Repeated letters and repeated words remain structurally visible. Trifid disrupts that simple relationship.
Once a block's coordinates are mixed, the ciphertext letter in a particular position may draw its first, second and third coordinates from different plaintext positions. The same plaintext character can therefore contribute to several ciphertext characters, while a ciphertext character can reflect information from several plaintext characters. This provides a limited form of diffusion: a change to one plaintext letter may affect more than one ciphertext letter within the same block. It also interferes with some of the easiest frequency-analysis attacks against simple substitution. A frequent plaintext letter does not invariably produce the same ciphertext letter.
However, Trifid should not be called modern polyalphabetic encryption merely because its substitutions change with context. It is best described as a fractionating substitution-transposition system. The changing behaviour comes from rearranging coordinates in blocks, not from cycling through independent substitution alphabets in the Vigenère manner. The distinction is technical, but useful. Cryptographic systems can obscure patterns in different ways, and not every system that breaks one-to-one letter correspondence is a Vigenère-style cipher.
The Cipher's Main Weaknesses
Trifid is more elaborate than Atbash or Caesar, but it is not secure. Its sophistication is relative to other manual classical ciphers.
The Rearrangement Is Fixed and Predictable
Once the period is known, the same coordinate permutation occurs in every block of that length. That gives an analyst a repeated structure to investigate. The cube may be unknown, but the overall method is not random.
Mixing Stops at Block Boundaries
Trifid does not spread information throughout an entire message when it uses a short period. Each block is encrypted independently. An attacker can examine repeated blocks, candidate periods and relationships between corresponding positions across messages. Reusing the same key and period for a collection of ciphertexts gives the analyst substantially more material to work with.
Very Short Periods Reveal Too Much
With period one, the cipher is the identity: plaintext and ciphertext are identical. Other small periods constrain how far information can move. Some periods create especially regular alignments in the coordinate regrouping. This is one reason traditional descriptions pay attention to the relationship between the period and the number three.
Human-Readable Keys Are Predictable
A cube built from a person’s name, a famous phrase or a common word is easier to reconstruct than an arbitrary cube permutation. The fact that the historical example uses its inventor's name is excellent for teaching, but would not be a good security practice.
Language and Repetition Still Leave Clues
Fractionation disrupts straightforward single-letter counts, but it does not abolish the statistical structure of language. Sufficient ciphertext, known plaintext, probable words, repeated messages and information about the key can all help an analyst. These weaknesses do not mean every short Trifid cryptogram is easy to solve by hand. An isolated message with little context may be challenging. But “sometimes difficult to solve casually” is not the standard required for secure communication. The cipher's design is public, its structure is deterministic and there are established classical methods for attacking fractionating systems.
How Trifid Can Be Broken
Cryptanalysis starts by asking what can be learned without knowing the cube. If the analyst suspects Trifid, an important early task is to determine or test the period. Once the period is known, the analyst knows how plaintext coordinate components would have been rearranged before turning into ciphertext symbols. That does not immediately reveal the cube. But it supplies an important structural constraint.
With sufficient ciphertext, the analyst can then search for recurring patterns, probable words and consistent relationships among the unknown coordinate assignments. Several messages made with the same cube and period are more useful than one isolated message. A known plaintext fragment is especially valuable. If the analyst knows or strongly suspects that a particular block corresponds to a particular word or phrase, its original coordinates and the ciphertext's coordinates must fit the same cube. Those relationships can be used to constrain candidate positions.
William F. Friedman's Military Cryptanalysis, Part IV discusses the solution of Trifid systems after treating related Bifid techniques. His treatment stresses the value of discovering the period and accumulating repeated or predictable plaintext material. This is historical evidence that Trifid was regarded as analytically tractable, not invulnerable. A conceptual attack therefore looks something like this:
- Identify Trifid as a plausible cipher family from the ciphertext and surrounding clues.
- Try likely periods and consider how the coordinate streams would line up.
- Look for repeated passages or use probable words if context supports them.
- Infer constraints on the unknown cube from how plaintext and ciphertext components must correspond.
- Reconstruct candidate cube assignments and test whether they decrypt the message into coherent language.
Software can automate portions of this search, but the underlying weakness remains classical: the structure of the encryption and the statistics of language give the attacker information. Trifid is harder to recognise than a fixed alphabet reversal. It is not beyond analysis.
Trifid Compared with Other Classical Ciphers
Different ciphers protect different aspects of a message. Comparing them shows what Delastelle was trying to improve.
Trifid vs Atbash
Atbash has one fixed mapping: A becomes Z, B becomes Y, and so on. Applying the same reflection twice restores the message. Trifid uses a keyed cube and a block-wise rearrangement of three-coordinate representations. Its decryption must undo the mixing, rather than simply applying the same substitution a second time. Atbash is about symmetry. Trifid is about fractionation and recombination.
Trifid vs Caesar
Caesar shifts every letter by a fixed number of alphabet positions. The same plaintext letter always produces the same ciphertext letter, and an attacker can simply test the small number of possible shifts. Trifid's output depends on how coordinates are mixed inside a block. Ordinary Caesar-style brute force is not an appropriate attack because there is no single alphabet shift to discover.
Trifid vs Bifid
This is Trifid's closest relative. Bifid turns each letter into two coordinates, generally using a 5×5 square, then separates and recombines those coordinates over a selected period. Trifid uses three coordinates and a 3×3×3 cube. It accommodates 26 letters without merging I and J, and has room for an extra symbol. Both are fractionating systems. Trifid extends the basic idea into another dimension, although that fact alone does not establish that every Trifid configuration is stronger than every Bifid configuration.
Trifid vs Vigenère
Vigenère changes the substitution applied to letters according to a repeated keyword. It is usually described as a polyalphabetic substitution cipher. Trifid does not cycle through a sequence of Caesar alphabets. Its apparent variation arises from splitting and transposing letter coordinates within blocks. Both are vulnerable to classical cryptanalysis, but the attacks focus on different structures.
Trifid vs Playfair
Playfair encrypts pairs of letters using a 5×5 keyed square. This conceals some ordinary single-letter frequency patterns by working with digraphs. Trifid works on a stream of three-part coordinates and can mix information across a larger block. Playfair is a digraph substitution; Trifid is a fractionating system.
Trifid vs ADFGVX
ADFGVX is another famous fractionating cipher, but it uses a 6×6 Polybius square to represent characters with two coordinate symbols, followed by a separate columnar transposition. Trifid carries out its mixing by rearranging three coordinate streams within successive blocks. Both illustrate the larger idea that substitution and transposition can be combined rather than treated as alternatives.
Using the CipherRegister Trifid Tool
The accompanying tool makes the internal operations visible as well as returning a ciphertext string. Start with Load example to select the Delastelle keyword cube, set period five, and load the historical French message. The output should be FMJFV OISSU FTFPU FEQQC.
Then inspect the three cube layers. Clicking a symbol reveals its coordinate; examining the first message block shows how the layer digits, row digits and column digits form a new sequence. Once that makes sense, try changing the period. The same message will usually encrypt differently because the coordinate components are being regrouped across different block boundaries.
Next, enter a different keyword and choose Use keyword. The tool removes repeated letters and constructs a new cube, so the same plaintext and period now produce a different ciphertext. Finally, use Swap input/output to decrypt. The key cube and period must remain the same.
A few details are worth remembering when comparing the tool with other online implementations:
- CipherRegister uses
.as its 27th cryptographic symbol. Some historical implementations use+or another agreed character. - Spaces, commas, apostrophes and other unsupported punctuation are not part of the cryptographic alphabet. They can be removed or optionally carried through as unchanged presentation characters.
- Grouping output into five-letter chunks is formatting. It is separate from the fractionation period, which changes the cipher, even when both settings happen to use the number five.
- Restoring the exact original spacing and punctuation after decryption is not always possible if those characters were discarded during encryption.
A Small Python Implementation
Trifid is a useful programming exercise because it brings together indexing, coordinate conversion, list manipulation and the inverse of a permutation. The implementation below matches the CipherRegister tool's essential conventions: letters A–Z, a dot as the 27th symbol, a keyword-derived cube and a positive fractionation period. It removes unsupported punctuation and spaces before encryption.
Python exampleShow code
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."
def make_cube(keyword):
letters = "".join(dict.fromkeys(
c.upper() for c in keyword
if c in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
))
return letters + "".join(c for c in ALPHABET if c not in letters)
def coords(index):
return f"{index // 9 + 1}{(index % 9) // 3 + 1}{index % 3 + 1}"
def trifid(text, keyword, period=5, decrypt=False):
if type(period) is not int or period < 1:
raise ValueError("Period must be a positive integer")
cube = make_cube(keyword)
to_digits = {symbol: coords(i) for i, symbol in enumerate(cube)}
to_symbol = {code: symbol for symbol, code in to_digits.items()}
message = "".join(c.upper() for c in text
if c in ALPHABET + "abcdefghijklmnopqrstuvwxyz")
result = []
for start in range(0, len(message), period):
block = message[start:start + period]
triples = [to_digits[c] for c in block]
width = len(block)
if not decrypt:
# Gather all first, then second, then third coordinates.
stream = "".join("".join(t[row] for t in triples)
for row in range(3))
codes = [stream[i:i + 3]
for i in range(0, len(stream), 3)]
else:
# Undo fractionation: split into three equal rows.
stream = "".join(triples)
rows = [stream[i * width:(i + 1) * width]
for i in range(3)]
codes = ["".join(rows[row][i] for row in range(3))
for i in range(width)]
result.extend(to_symbol[code] for code in codes)
return "".join(result)
message = "AIDE-TOI, LE CIEL T'AIDERA"
keyword = "FELIX MARIE DELASTELLE"
ciphertext = trifid(message, keyword, period=5)
plaintext = trifid(ciphertext, keyword, period=5, decrypt=True)
print("Encrypted:", ciphertext)
print("Decrypted:", plaintext)
Expected output:
Encrypted: FMJFVOISSUFTFPUFEQQC
Decrypted: AIDETOILECIELTAIDERA
Notice that the code does not preserve the original hyphen, comma, spaces or apostrophe. Those symbols are discarded during preprocessing, so decryption correctly restores the letters rather than the full original typography. The main encryption idea appears in this expression:
stream = "".join("".join(t[row] for t in triples)
for row in range(3))
It walks across the list of triplets by coordinate position: all first digits, all second digits, then all third digits. That is fractionation in a single expression. The decryption branch performs the inverse. It splits the stream into three equally sized coordinate rows and rebuilds each original triplet by taking one digit from each row. The underlying logic is straightforward. The result is less so, because small changes in how coordinates are rearranged can alter several output letters.
What Trifid Still Teaches Us
Trifid does not belong in modern secure messaging. It should never be used to protect passwords, financial details, personal correspondence or other sensitive information. Its key handling, deterministic structure and resistance to cryptanalysis fall far short of what is expected from contemporary encryption.
Trifid remains valuable because it shows that a cipher can work on representations of symbols, rather than treating each letter as an indivisible unit. An A can become a sequence of coordinates whose components are separated, moved and recombined with components from other letters. The result is a conceptual shift from the simple substitution ciphers that dominate introductory exercises: the cipher changes which pieces of information belong together.
Trifid's mixing is local and rigid, while modern cryptographic systems use more elaborate constructions with repeated rounds, nonlinear transformations and carefully studied security properties. It is a historical illustration of a design idea, rather than something to equate mechanically with a modern block cipher. The 3×3×3 cube gives it a distinctive appearance, but the ingenuity lies in what happens after letters leave their positions and their coordinates are rearranged.
The Real Lesson of Trifid
Atbash reverses the alphabet. Caesar shifts it. Vigenère changes the shift. Trifid does something different: it divides letters into coordinates and changes how those coordinates belong together. The process starts with an ordinary message, passes through a numerical representation, and returns to an apparently ordinary stream of letters. Along the way, relationships that were obvious in the original text become much less direct.
That makes Trifid a particularly satisfying cipher to explore visually. Its output can look arbitrary, but every letter has a traceable explanation. Nothing is magic. Nothing is random once the cube and period have been chosen. Its weaknesses are equally instructive. A complex-looking mechanism does not automatically provide modern security. Repeated structure, human-generated keys and language statistics still matter.
Trifid sits in an interesting position in the history of cryptography: more subtle than a simple substitution, more intricate than a straightforward rearrangement, but still transparent enough to understand with pencil, paper and a little patience. Its essential lesson is that sometimes the best way to conceal a letter is not to replace it, but to take it apart.