© 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:
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):
When encrypting, we may end with a transposition, this way:
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
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.
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.
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
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):
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.
Information about output randomness will appear here
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.