# Serpentine encryption

This is a reversible cipher based on Baise de Vigenère's classic autokey cipher, including a substitution and involving five letters at a time rather than only one. The basic pattern is a kind of serpentine on the Tabula Recta, hence the name. It is also possible to select an autokey seed that is different from the substitution key.

The first step is to generate a scrambled alphabet from the substitution key. The process is simple: 1, take the key and write down new letters in the order they appear; if a letter in the text key 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 also make a "negative" alphabet by taking the first letter of the scrambled alphabet, and then the rest of its letters in reverse order. Place the scrambled alphabet on the top and left side of the Tabula Recta, and the negative alphabet on the bottom and right.

After the plaintext or ciphertext and the seed are 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— we perform the operations described below, which are the same for encryption and decryption. Since the first phase has less security, you may want to prepend a number of gibberish letters equal to the length of the seed, the better to mask the seed against cryptanalysis.

This is what you do to encrypt or decrypt:

1. Take the seed and write it directly above the plaintext (or ciphertext; for brevity's sake, we'll just call it "plaintext" in either case from now on) beginning with the leftmost position.
2. Take the first plaintext letter, look it up on the top of the Tabula Recta, and go down until the seed letter directly above that letter is found, then left to the edge (you can also start on the left and end at the top). Write that letter below the plaintext letter. Then take the second plaintext letter and do the same, this time using the second seed letter, and so on. When this phase is over, the row below the plaintext will contain the same number of letters as the seed.
3. From now on, we do serpentine operations involving five letters: the letter immediately above the spot we want to fill, plus two letters on the left of it on the same row, the first at a distance equal to the length of the seed, and the one following it, plus the two letters below those. Start this way: take the plaintext letter above the spot to be filled and look it up at the top of the Tabula Recta, then go down until the first plaintext letter (top row) is found, then left or right until you find the second plaintext letter (directly right of the previous, in the work table), then up or down to find the third letter (directly down from the second), then left or right to find the fourth (directly right of the fourth), and finally down to read the result at the bottom. Alternatively, you can start on the left and end on the right, switching direction with each new letter. Mark the first column used so you don't use it again. Then look at the next empty spot the next letter and do the same, this time involving the next pair of consecutive plaintext letters, on the top row. Keep repeating this step while the bottom row is shorter than the top row. When done, the bottom row is the ciphertext (plaintext when decrypting).

### 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

## Step 1. Tabula preparation

We begin by making a scrambled alphabets out of the key, which is then placed at the top and left of the Tabula Recta, plus its negative version at right and bottom. This is why we input the key before the plaintext. The boxes are blue to indicate that they can be written on. Do this to make a scrambled alphabet: take the key and write the different letters of the alphabet in the order they appear in the key, if a letter has been used already, write instead the immediately preceding letter in the normal alphabet not yet chosen; if there are letters that did not appear in the key, write them now in reverse alphabetical order. To make the negative version take the leftmost letter, and then on the right of it write the rest of the letters in reverse order.

It is OK to use a key and seed that have been used before, even for a message of identical length as a previous message.

### Key

If you want to use as a seed something different from the key, write it in this box, otherwise the key will be used for this:

## Step 2. Plaintext preparation

### Plaintext / Ciphertext

For best security when encrypting, prepend a number of random characters (nulls) equal to the seed length

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

## Step 3. Encryption / Decryption

In order to obtain the ciphertext we generate the table below, following the instructions at the top of this page. The bottom row is the output.

### Work table

Information about output randomness will appear here

## Step 4. Encrypted Ciphertext / Decrypted Plaintext

The ciphertext (plaintext when decrypting) is the first box below. The lower box contains the same, but split into codegroups of five characters each. Complete the last one with random letters if you need to; they will decrypt to gibberish.