✖

Rail fence cipher and scytale: steps and converter

The rail fence cipher, in Czech also called the zigzag cipher (“cik-cak šifra”), writes a message in a zigzag over several rows and then reads it off row by row. The letters stay the same, they are just shuffled. Ciphers like this are called transposition ciphers, and the Spartan scytale is one of them. Take the message “útoč za svítání” (Czech for “attack at dawn”, written without spaces and accents) and two rows: the first letter goes up, the second down, the third up again, and so on.

The letters U, T, O, C, Z, A, S, V, I, T, A, N, I alternating between a top and a bottom row, and below them the cipher UOZSIAI TCAVTN The letters U, T, O, C, Z, A, S, V, I, T, A, N, I alternating between a top and a bottom row, and below them the cipher UOZSIAI TCAVTN

First we read the top row, UOZSIAI, and attach the bottom row, TCAVTN, after it. The ciphertext is UOZSIAITCAVTN. Unlike Atbash or the Polybius square, no letter has been given a different shape here.

The rail fence cipher with three rows

With three rows the letters are shuffled more: the zigzag goes down to the third row, back up to the first, and down again. The letters trace out the zigzag of a fence, which is where the cipher gets its name.

The letters of the message UTOCZASVITANI drop one by one in a zigzag into three rows, the first row red, the second blue, the third green; then the rows are highlighted one after another and their letters are written under the zigzag as UZII TCAVTN OSA The letters of the message UTOCZASVITANI drop one by one in a zigzag into three rows, the first row red, the second blue, the third green; then the rows are highlighted one after another and their letters are written under the zigzag as UZII TCAVTN OSA

The first row holds U, Z, I, I, the second T, C, A, V, T, N and the third O, S, A. The cipher is therefore UZIITCAVTNOSA.

The number of rows is called the key. The sender and the receiver must know it, and nobody else.

Rail fence cipher converter

Type in a message and the number of rows. The converter drops spaces, punctuation and Czech accents and writes in lower case. To decrypt, use the same number of rows that the sender used.

The default text is the Czech “Útoč za svítání”, the message from the example above.

How to decrypt a rail fence cipher by hand

We have UZIITCAVTNOSA in front of us and we know the key is 3. We just don’t know where the first row ends and the second begins. Let’s work it out.

A zigzag starts in the top row, goes down, comes back up and ends just before the next letter of the top row. With n rows, one zigzag has

2⋅(n−1)

letters: n − 1 steps down and n − 1 steps up. The top and bottom rows take one letter from each zigzag, and every middle row takes two (one on the way down, one on the way up). For three rows a zigzag has 2 · 2 = 4 letters: one for the first row, two for the second and one for the third.

Our message has 13 letters, which is three whole zigzags and one extra letter:

13=3⋅4+1

The whole zigzags put 3 · 1, 3 · 2 and 3 · 1 letters into the rows, that is 3, 6 and 3. The remaining letters belong to the next, unfinished zigzag and follow its path: the first goes up, the next into the second row, and so on. Here there is only one, and it ends at the top. The rows therefore hold 4, 6 and 3 letters.

Thirteen empty circles arranged in a zigzag over three rows; on the right the first row is marked 4, the second 6 and the third 3 Thirteen empty circles arranged in a zigzag over three rows; on the right the first row is marked 4, the second 6 and the third 3

We split the cipher by these counts: the first 4 letters UZII, the next 6 TCAVTN and the remaining 3 OSA. We write each group from left to right into the circles of one row and then read the circles in zigzag order. We get UTOCZASVITANI, that is “útoč za svítání”.

The scytale: a cipher wound around a stick

A scytale is a stick around which a narrow strip of leather or parchment is wound at a slant, coil next to coil. The message is written along the stick, and once the strip is unwound it shows only a row of jumbled letters. It can be read by anyone who winds the strip around a stick of the same thickness.

Take a thin stick and the message “Lysandre, vrať se domů” (Czech for “Lysander, come back home”). Three letters fit around the stick in one coil. We write the message along the stick: the first row LYSAND spreads over six coils, with one letter on each. Then we turn the stick, write REVRAT next to it, and finally SEDOMU. So there are three rows (that is how many letters fit around the stick) and six columns (that is how many coils there are).

A stick wound with a strip of six coils, with LYSAND written in red along the stick; below it the unwound strip LRSYEESVDARONAMDTU, where red, blue and green letters alternate in threes, numbered 1 to 6 A stick wound with a strip of six coils, with LYSAND written in red along the stick; below it the unwound strip LRSYEESVDARONAMDTU, where red, blue and green letters alternate in threes, numbered 1 to 6

On the unwound strip the coils lie side by side, and each carries one letter from every row. This makes a table into which we write the message row by row:

1 2 3 4 5 6
Row 1 L Y S A N D
Row 2 R E V R A T
Row 3 S E D O M U

and read it column by column: LRS, YEE, SVD, ARO, NAM, DTU. The cipher is LRSYEESVDARONAMDTU. The key is the circumference of the stick, that is, the number of rows in the table. Decryption works the other way round: we write the cipher into the table column by column and read it row by row. The number of columns is the length of the message divided by the circumference, here 18÷3=6.

When the length of the message is not a multiple of the circumference, the number of columns is rounded up, and empty cells are left at the end of the table (on the right in the last row). When decrypting by hand, mark them first and fill in the columns using only the full cells. The converter does this for you.

Transposition ciphers and how to break them

Atbash, the number cipher and the pigpen cipher are all substitutions: they swap every letter for something else but leave it in its place. Transposition does exactly the opposite.

You can recognise it by the letter frequencies in the cipher: they come out the same as in ordinary Czech, and the most common letters will be E, A, O, I. With a substitution, different letters would come out on top. Frequency analysis therefore reveals that the letters have been shuffled, but it does not say how they were shuffled.

Breaking the rail fence cipher is not hard, though, because there are few keys. For a message of 13 letters it only makes sense to try 2 to 12 rows, that is 11 possibilities (one row, or 13 or more rows, leaves the message unchanged). You just run through them in the converter and pick the one that produces Czech. The scytale is the same: the codebreaker tries different circumferences.

Where the scytale comes from

The scytale is attributed to Sparta. The best-known description comes from the Greek writer Plutarch, around the turn of the 1st and 2nd centuries AD: according to him, this is how Spartan officials recalled the commander Lysander home at the end of the 5th century BC. No scytale has survived. Some historians think it was more a staff for authenticating a messenger, or an ordinary letter, than a cipher; others disagree. The rail fence cipher is younger and little is known about its origin. Today it is popular at summer camps: everyone can remember the key, and you can crack a message with just a pencil.