# Snake encryption

This page simplifies the paper-and-pencil TripleText cipher by F. Ruiz so the Tabula Recta is used more efficiently. All steps can be performed by hand without excessive effort.

We will use a piece of key text typically three times the length of the plaintext (after spaces and punctuation are removed) in order to generate a "one-time pad" of sorts by concentrating the entropy inherent in the key text to match that of a perfectly random text. The key difference between this cipher and the classic running key cipher is that the latter uses a piece of key text of the same length as the plaintext, which is less than perfectly random and can be attacked by making guesses from a dictionary. As dictionary words, or parts thereof, are obtained when other dictionary words are subtracted from the ciphertext (at different positions in the ciphertext), then both the plaintext and the key text are gradually recovered at the same time. This is not possible with this cipher.

Theoretical unbreakability is achieved when the keystream used to encipher the plaintext has the same entropy as a random string of the same length, according to Shannon's criterion for perfect secrecy. Since there are 26 possible letters, the entropy of a perfectly random string or letters is log(26)/log(2) = 4.70044 bits/letter. Since English text, according to Shannon, has an average entropy of 1.58 bits per character (spaces are included, so the entropy per letter is a little higher), a piece of text of length 4.70044/1.58 = 2.975 times the length of a given random string contains the same entropy. If the text is three times as long as the plaintext, therefore, its entropy can match that of a random string of plaintext length.

The process is identical for encryption and decryption. After the plaintext or ciphertext is processed —spaces and punctuation are stripped, and all letters are converted to capitals; accented letters are replaced by their non-accented versions; numbers in plaintext are converted to letters as in 0=A,1=B,...9=J, but are not converted back— a piece of equally processed key text three times (or another odd number) as long as the processed plaintext or ciphertext is selected, split into parts of equal length, and written below the plaintext as three additional lines. Then each four-letter column in the resulting table is processed using the Tabula Recta below, this way: find the first letter at the top and go down until the second letter is found, then left or right following that row until the third letter is found, then up or down on that column until the fourth letter is found, and then left or right to read off the result at the edge columns. Alternatively, you can start on the side rather than the top, switching direction every time a new letter is found, and read the result at the top.

If a key-derived alphabet is used, rather than the straight alphabet, this operation also involves a substitution on the plaintext. Using an alphabet derived from the key text makes the final ciphertext non-malleable.

### Tabula Recta

  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
---------------------------------------------------
A | A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | A
B | B C D E F G H I J K L M N O P Q R S T U V W X Y Z A | B
C | C D E F G H I J K L M N O P Q R S T U V W X Y Z A B | C
D | D E F G H I J K L M N O P Q R S T U V W X Y Z A B C | D
E | E F G H I J K L M N O P Q R S T U V W X Y Z A B C D | E
F | F G H I J K L M N O P Q R S T U V W X Y Z A B C D E | F
G | G H I J K L M N O P Q R S T U V W X Y Z A B C D E F | G
H | H I J K L M N O P Q R S T U V W X Y Z A B C D E F G | H
I | I J K L M N O P Q R S T U V W X Y Z A B C D E F G H | I
J | J K L M N O P Q R S T U V W X Y Z A B C D E F G H I | J
K | K L M N O P Q R S T U V W X Y Z A B C D E F G H I J | K
L | L M N O P Q R S T U V W X Y Z A B C D E F G H I J K | L
M | M N O P Q R S T U V W X Y Z A B C D E F G H I J K L | M
N | N O P Q R S T U V W X Y Z A B C D E F G H I J K L M | N
O | O P Q R S T U V W X Y Z A B C D E F G H I J K L M N | O
P | P Q R S T U V W X Y Z A B C D E F G H I J K L M N O | P
Q | Q R S T U V W X Y Z A B C D E F G H I J K L M N O P | Q
R | R S T U V W X Y Z A B C D E F G H I J K L M N O P Q | R
S | S T U V W X Y Z A B C D E F G H I J K L M N O P Q R | S
T | T U V W X Y Z A B C D E F G H I J K L M N O P Q R S | T
U | U V W X Y Z A B C D E F G H I J K L M N O P Q R S T | U
V | V W X Y Z A B C D E F G H I J K L M N O P Q R S T U | V
W | W X Y Z A B C D E F G H I J K L M N O P Q R S T U V | W
X | X Y Z A B C D E F G H I J K L M N O P Q R S T U V W | X
Y | Y Z A B C D E F G H I J K L M N O P Q R S T U V W X | Y
Z | Z A B C D E F G H I J K L M N O P Q R S T U V W X Y | Z
---------------------------------------------------
  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

We are going to perform a special kind of addition (actually, a subtraction followed by a change of sign) using this table. To "add" two letters: find the first letter on the left or right side and follow that row until you find the second letter, then go up that column to read the result at the top row or you find the lext letter to "added". Examples with straight alphabet: R + H = Q, E + W + F = N, Z + A + J + X = P.

## Step 1. Tabula preparation

We begin by making a scrambled alphabet out of the key text, which is placed at the top of the Tabula Recta, and then repeated in the body itself. This is why we input the key text before the plain text. The box is blue to indicate that it can be written on. Do this to make a scrambled alphabet: 1, take the first sentence in the key text (up to the first period) and write down new letters in the order they appear; if a letter in the key text has already been written, write instead the first letter before it in the alphabet that is still available (wrap around to the end if needed); 2, then write the rest of the alphabet in reverse order. Then take the same scrambled alphabet and write it on the leftmost column.

When a plaintext is written, the key text is processed in the same way as the plaintext (capitals rather than lowercase). If it is too short, it will be repeated and a warning will appear below the key text. This key text will be used to encrypt the plaintext (or decrypt the ciphertext), and then it will never be used again.

### Key Text

This is where the warning will appear

Let us also select whether the alphabet that forms the basis of the Tabula Recta will be scrambled according to the key text, or the straight alphabet will be used:

Key text-derived alphabet     Straight alphabet

## Step 2. Plaintext preparation

Now the message to be encrypted.

### Plaintext / Ciphertext

Which is converted to this, after spaces, punctuation and diacritics are removed, and everything is turned into lowercase:

## Step 3. Encryption / Decryption

The next step is to generate the ciphertext. In this version, we can enter in the box below a variable multiplier for the key text length, but it must be an odd number. Typically, 3 times the plaintext length is enough.

### Key Text length factor

Allowed values are 1, 3, 5, 7, and 9. This is how many times the key text is longer than the plaintext.

Now we take a piece of the key text equal to that many times the length of the processed plaintext and place it underneath the plaintext, forming as many extra rows, resulting in this:

### Plaintext/Ciphertext plus Processed Key Text

And then we "add" the letters in each column using the Tabula Recta, as described above (first to second, then the result to third, and so on) in order to obtain the ciphertext (or plaintext), shown below.

Information about ciphertext randomness will appear here

## Step 4. Encrypted Ciphertext / Decrypted Plaintext

The lower box contains the same, but split into codegroups of five characters each.