FibonaRNG encryption

© Francisco Ruiz, 2016

FibonaRNG (pronounced as "fibonaring") is a cipher based on the Visionnaire cipher, which is in turn based on Blaise de Vigenère's classic autokey cipher, adding substitutions at the input and output of the Tabula Recta. This implementation also adds an optional transposition. The user can select two different substitution keys, plus a separate seed. While Visionnaire obtains randomness from the plaintext itself, FibonaRNG obtains it from the keys and seed alone by means of a lagged Fibonacci generator, which makes it suitable for low-entropy plaintexts. You can reuse the same set of keys and seed for two different messages if you are using a random seed, otherwise it is best to alter them for different messages, perhaps by adding to one of them a serial code that gets transmitted along with the message.

The first step is to generate a scrambled alphabet for each substitution key and the transposition 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 (this is done only for the substitution alphabets, not for transposition). Place alphabet 1 on the left side and right sides of the Tabula Recta, alphabet 2 on the top and bottom.

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 might do a reverse transposition if decrypting:

  1. Take the third scrambled alphabet and write it down on checkered paper. Measure the length of the ciphertext up this point and divide that by the length of the alphabet. 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.
  2. Write the ciphertext 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, left to right. This is the descrambled ciphertext.

Then we do the main encrypt/decrypt process, which goes as explained below. We will assume we are using a random seed for the message; if not, the process is simplified as noted (when decrypting, the role of the plaintext in the instructions is played by the ciphertext descrambled in the previous step):

  1. If encrypting, write a string of random letters as long as the seed, which will become the random seed, and then the plaintext immediately to its right. If using the straight seed simply leave an empty space of that length and then write the plaintext. When decrypting, just write the ciphertext.
  2. Take the seed and write it at the start of the line below the plaintext (if using a straight seed, below the empty space so it ends right before the plaintext begins on the line above).
  3. If decrypting, extract the random seed from the ciphertext by following the process in step 5 just for those few letters, bearing in mind that you look up the top letters on the left or right of the Tabula Recta, and write into the bottom row the letter found at top or bottom of the table. Skip this step if encrypting or using the straight seed.
  4. Extend the seed (start of the first row if encrypting, of the third row if decrypting, of the second row if using the straight seed) into a keystream so all spaces in the second row are filled, this way: Look up the first keystream letter still available at the top or bottom of the Tabula Recta, then down until you find the letter that follows it in the keystream, then go left to read a letter on the right or left alphabet, which you will write in the next available position below the plaintext. Mark the first keystream letter you looked up so next time you start with the next letter. Notice that when encrypting you start taking letters from the top row, but when you run out of random seed you continue taking them from the second row, never from the plaintext itself.
  5. Now do the following for each pair of letters consisting of a plaintext letter and the letter right below it: Look up the plaintext letter at the top or bottom of the Tabula Recta, then go up until you find the letter below, then right to read a letter on the right or left alphabet, which you will write below the pair of letters you involved in this operation, forming the ciphertext. Alphabet order is reversed for decryption.

When encrypting, we may end with a transposition, this way:

  1. Take the third scrambled alphabet and write it down on checkered paper.
  2. Write the result of the previous step 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 ciphertext.

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 scrambled alphabets out of the keys, which are then placed at the top and bottom of the Tabula Recta. This is why we input the keys before the plaintext. The boxes are blue to indicate that they can be written on. Do this to make a scrambled alphabet: take each 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 (keys 1 to 3 only).

It is OK to use keys that have been used before, even for a message of identical length as a previous message. The straight alphabet is used for key 2 if its box is left empty. If the key 3 box is empty, key 1 is used for this role too. Write a single letter in the key 3 box to turn off transposition.

Key 1

Key 2

Key 3 (transposition)

If you want to use for the seed a string different from key 1, write it in this box, otherwise key 1 will be used. The seed should be at least three characters long. This is a good place to add a serial, if using the straight seed.

Seed

Here we tell the program whether or not to use a random seed of the same length instead, which is prepended to the plaintext before the keystream is added:

     Random seed     Straight seed

Since the process is different for encryption and decryption, we have to tell the program what we want to do:

     Encrypt     Decrypt

 

Step 2. Plaintext preparation

Plaintext / Ciphertext

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

Processed Plaintext / Ciphertext

If we are decrypting, the ciphertext may need to be descrambled using key 3 as transposition key. This is the result (same when encrypting, except perhaps prepending a random seed):

 

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 top row is the input, the middle row the keystream, the bottom row the output.

Work table

Information about output randomness will appear here

 

Step 4. Encrypted Ciphertext / Decrypted Plaintext

When encrypting, we might do a transposition as final step, using key 3 as key. We begin with the result of the previous operation, which will be repeated if we are decrypting instead (transposition was done earlier).

The ciphertext (plaintext when decrypting) is the first box below. The lower box contains the same, but split into codegroups of five characters each. If a random seed was added to the ciphertext, it is stripped now.

Ciphertext / Plaintext

Formatted output