© Francisco Ruiz, 2016

This page implements the paper-and-pencil "Aphid" cipher by F. Ruiz, for those who wish to use a computer as a convenience. All steps can be performed by hand without excessive effort. The process is described in detail in this article.

Aphid uses a passphrase made of at least two words. A 5x5 Polybius square is then used to encode the letters in the plaintext into pairs of digits 0-4. Then each word of the passphrase is used as key of a columnar transposition. If a word has less than four characters, it will be merged with the next for this purpose. Finally, the digits are encoded back to letters, and those are transmitted out.

To decrypt, the letters are split into digits using the Polybius square, then transpositions are reversed in reverse order, and then the digits are decoded back to letters. The whole process is quite fast since transpositions are fast.

First let us enter the passphrase in the box below, which is shaded blue like all the other boxes where you can enter something.

A key-derived square would be made this way: take the passphrase and start filling the square, by rows, with the different letters and digits that appear as you read the sentence (I and J are considered the same letter); then follow with the rest of the letters in reverse order. The resulting square is shown below. This will be the default square if so selected in the settings:

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

To encode using the square, simply replace each letter or digit with the row number followed by the column number, ignoring spaces and punctuation. Examples with default encoding: s = 33, H = 12, C = 02.

Let us now tell the program what we want to do by checking one of the two buttons below. The difference is that the transpositions are performed in reverse order.

Encrypt Decrypt

And let us also decide whether or not we are basing the encoding on the key text. **Warning:** encrypted messages using default encoding can be altered by an adversary, plus the key text can be recovered if the plaintext is known.

Key text-derived square Default square

Now we write the plaintext that we wish to encrypt, which will be converted to lowercase. Spaces and punctuation marks are ignored. Diacritical marks (accents) are ignored. All J's are converted into I's. If there are any numbers, they are first converted to letters as in a = 1, ... i = 9, k = 0. Plaintext numbers are not decoded back upon decryption, but hopefully the user can spot them easily.

And this is the same text, encoded as decimal digits. If now you type into the Encoded Plaintext box, its contents are automatically decoded and the result placed in the Plaintext box. When decrypting a ciphertext already encoded as digits, we start with the next box.

The next step is to transpose this, using each word of the passphrase as a permutation key. A permutation key contains the integers 0 to N, where N is the number of rows (which may be partially filled), in an order different from normal. The process to obtain it is as follows: 1. Find the letter in the word that is the first in alphabetical order and mark that with 0, then mark the next one with 1, and so on until all are marked. 2. if a letter appear twice, give a number first to the one appearing latest in the word, then the next to last, and so on.

The table below shows the permutation keys obtained:

And now we apply each one to the encoded plaintext. We do it this way: 1. Write the permutation key, and below it the plaintext making consecutive rows of the same length until the plaintext is exhausted. 2. Then read off the table by columns, beginning with the one with "0" at the heading, then the one headed by "1", and so on. Some columns may be longer than others. The result of each transposition is represented as a row in the table below. The final row is the ciphertext, which is repeated in the first green box.

If we are decrypting, the tables are filled by columns, following the order given by the key, and then read off by consecutive rows. The last word in the passphrase is used first, the first last.

Finally we decode the result back to letters using the encoding pattern: