# Letteracci encryption

© Francisco Ruiz, 2015

This page simplifies the paper-and-pencil Numeracci cipher by F. Ruiz so no encoding is used. Instead, operations are carried out directly on the text by means of a Tabula Recta, which implements addition and subtraction mod 26 over a 26-letter alphabet. All steps can be performed by hand without excessive effort.

We will use a piece of key text the length of the plaintext (after spaces and punctuation are removed), plus one in order to generate a "one-time pad" of sorts by processing the key text through a lagged Fibonacci generator (LFG) so it has better statistical randomness. The key difference between this cipher and the classic running key cipher is that the latter uses less than perfectly random text as keystream 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. In order to provide more resistance against brute force and approach the perfect undecipherability of a one-time pad, a pseudo-Shannon compression can be applied to the key text before it is used to make a keystream; this compression has the effect of using three times as many words from the key text, resulting in a higher entropy.

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 is selected and further randomized by a lagged Fibonacci process, which involves mod 26 addition of letters using the standard Tabula Recta below. If a key-derived alphabet is used, rather than the straight alphabet, this operation also involves a substitution of the letters in the second term of the sum. Finally the plaintext (ciphertext, when decrypting) is subtracted letter by letter from the keystream (and substituted, if the alphabet is not the straight one). Using an alphabet derived from the key text makes the LFG step irreversible and 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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
---------------------------------------------------
    a z y x w v u t s r q p o n m l k j i h g f e d c b

To add two letters: find the first letter on the left side and the second on the top; then follow the row and column, respectively; the letter at the intersection of the two is the sum. Example with straight alphabet: R + h = Y. To subtract two letters (as in subtracting the plaintext from the keystream or the ciphertext from the keystream): find the first letter on the left and the second letter (the one being subtracted) on the bottom, and then follow those row and column to find the result at the intersection. Example with straight alphabet: R - h = K.

## 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 the Tabula Recta is filled by taking the top line and copying it below, and then displacing it cyclically to the left by one letter in each successive row. The bottom line, which is used for subtractions, is made from the top line this way: the first letter is the same, and then follow with the rest of the letters on the top line, in reverse order.

When a plaintext is written, the key text is processed in the same way as the plaintext (capitals rather than lowercase) and a piece of it one letter longer than the processed plaintext, is taken and placed in the seed box. 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

We first select whether this will be used as-is, or a pseudo-Shannon compression will be applied first. This consists of taking only the first letter from each word, for words containing four or fewer letters, or the first and last, for longer words:

No compression     Apply compression

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. Keystream Generation

The next step is to generate the keystream. In this version, we can enter in the box below the number of rows that the lagged Fibonacci generator will produce. Typically, 3 rows is enough.

### LFG rows

Allowed values are 1 to 9.

Because of the non-linearity of the LFG with a key-derived alphabet, it is possible to prepend a random nonce made of letters to the key text in order to reuse the key text. Here is were we optionally enter the nonce, which should never be reused with the same key text. This should not be done when using the straight alphabet.

### Nonce (optional, key-derived only)

We begin by taking a piece of the nonce + encoded key text that is one letter longer than the encoded plaintext, which will become the seed for the LFG. If the key text is not long enough, it will be repeated and a warning will appear below the key text box.

### Seed

Now the seed is used to initialize a lagged Fibonacci generator, where each letter after the seed is the sum, using the Tabula Recta, of the previous letter and the one located a number of spaces equal to the encoded plaintext length before the current letter. This is best done by rows, adding the letters immediately to the left of the one we are filling and the one above it. We stop when the set number of rows are completed. The process is initialized by putting the seed in row one, except for the last letter, which becomes the first in row two.

And take the last row as the keystream.

### Keystream

Information about keystream quality will appear here

## Step 4. Encrypted Ciphertext / Decrypted Plaintext

We now use the Tabula Recta to subtract and encode letter by letter the processed plaintext (ciphertext, when decrypting) from the keystream, resulting in the ciphertext (plaintext, when decrypting). The lower box contains the same, but split into codegroups of five characters each.