SuperWorm encryption

© Francisco Ruiz, 2016

The Worm cipher extends the Snake cipher, by F. Ruiz, so it can be used with relatively short keys (hence the name) rather than keys three times the length of the plaintext. Snake simplified the paper-and-pencil TripleText cipher, also by F. Ruiz, so the Tabula Recta was used more efficiently. SuperWorm is the Worm cipher with transpositions added at start and end to protect against a known-plaintext attack, to which Worm is susceptible. All steps can be performed by hand without excessive effort. The process is identical for encryption and decryption.

While Snake uses a non-repeating key text three times the length of the plaintext in order to generate the keystream, Worm uses a short repeating seed, as in the so-called Vigenère cipher, plus the plaintext and the ciphertext themselves after a delay equal to the length of the seed. After a short initial phase, letters are combined in groups of four as in the Snake cipher. The Tabula Recta includes a substitution determined by the main key (which can be different from the seed). There is another key for a transposition step. Unlike Snake, the Worm cipher can take keys or a seed that have been used before.

The first step is to generate scrambled alphabets from the substitution and transposition keys. 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 (this is done only for the substitution alphabet, not for transposition). Place the scrambled substitution alphabet on all sides of the Tabula Recta.

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— we transpose the result using the second scrambled alphabet as key. This way:

  1. Take the second scrambled alphabet and write it down on checkered paper.
  2. Write the processed plaintext in the cells below the alphabet by rows, left to right and top to bottom.
  3. Finally, read them off by columns, following the order marked by the alphabet: first the "A" column, then "B", and so forth. This is the scrambled plaintext. You may want to copy the cell pattern (without filling it with letters), which will be used again in the last step.

Now the main encryption takes place. We write the result of the transposition as a row of letters, and then two additional rows are written below it to make a work table. Second row is the seed, repeated as many times as needed to equal the length of the plaintext. Third row is the ciphertext, which is computed differently while the number of its characters does not exceed the seed length (initial phase), this way:

  1. For the initial phase, take the plaintext letter (top row), look it up on the top, bottom, or sides of the Tabula Recta, and then follow that row of column until the corresponding seed letter (immediately below the plaintext letter) is found, then follow that column or row, switching direction from the previous, to read the ciphertext letter on one of the edges. Keep doing this until you have used all the seed letters once.
  2. Each ciphertext letter after this is the result of a four-letter "snake" operation on the Tabula Recta, where one starts looking up the first letter at the top or bottom, then up or down to the second letter, then right or left to the third, then up or down to the fourth, and finally right or left to read the result on the sides. Alternatively, one can start at the sides and read the result at top or bottom, switching direction with each new letter. Draw the letters in this order: first is the letter immediately above the spot to be filled; second, third, and fourth are the letters on the column one seed length left of the spot to be filled, read from top to bottom. Mark each column right after using it, so it is clear which is the next column to be used. Repeat this until the third row of the work table is as long as the others. This third row is the pre-ciphertext.

One more operation is needed to obtain the final ciphertext (plaintext when decrypting). This is a reverse transposition using the second scrambled alphabet as key. It is done this way:

  1. Take the second scrambled alphabet and write it down on checkered paper. Measure the processed ciphertext length and divide that by key 2 length. Reserve as many empty rows below the alphabet as the integer result, rounded down, plus as many single cells below those, starting from the left, as the remainder. The reserved cells are the same as the cells filled with letters in the first transposition.
  2. Write the result if the last step in the reserved cells by columns, top to bottom, following the order marked by the alphabet: first the "A" column if any, then "B", and so forth, filling each column completely (some columns are longer than others).
  3. After filling all the reserved cells, read them off by rows, starting from the top row, left to right. This is the final 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  

Example 2-letter operations with straight alphabet: R + H = Q, E + W = S. Example 4-letter operations: Z + A + J + X = P, M + I + N + E = N.

 

Step 1. Tabula preparation

The main key is for making the mixed alphabet at the top, bottom, and sides of the Tabula Recta. Do this to make a scrambled alphabet: 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 immediately preceding 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 (key 1 only).

It is OK to use keys that have been used before, even for a message of identical length as a previous message. In this program, if you leave the key 2 box empty, key 1 will be used also as key 2. Write a single letter in the key 2 box to turn off transposition.

Key 1 (tabula recta)

Key 2 (transposition)

If you want to use a seed different from key 1, write it in this box. Otherwise key 1 will be used as seed:

Seed

 

Step 2. Plaintext preparation

Plaintext / Ciphertext

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

Now the message to be encrypted is converted to what follows after spaces, punctuation and diacritics are removed, and everything is turned into lowercase:

Processed Plaintext / Ciphertext

 

Step 3. First transposition

We begin by transposing the processed plaintext (processed ciphertext, if decrypting), using Key 2 as transposition key. This is the result:

Transposed Plaintext/Ciphertext

 

Step 4. Main encryption / decryption

The next step is to obtain the pre-ciphertext (pre-plaintext, if decrypting). We generate the table below, following the instructions at the top of this page. The third row cannot be made right away but only after the computation has started, but here you will see it in its final state. The output is the third row. Some statistics will be displayed below the table.

Work table

Information about output randomness will appear here

 

Step 5. Second transposition

We finish by performing a reverse transposition on the last line of the table above, which is repeated below. We use Key 2 to do the reverse transposition, and the result is the ciphertext (plaintext when decrypting)

The ciphertext (plaintext when decrypting) is in the first box below. The lower box contains the same after splitting into codegroups of five characters each.

Ciphertext / Plaintext

Formatted output