# Scrabble encryption

This is a cipher based directly on John F. Byrne's Chaocipher from 1918, which was kept secret for many years and finally revealed in 2010. It extends Chaocipher so that the alphabet letter to be moved to the nadir position can be varied rather than always use the same. It also applies a transposition after the main encryption process in order to defeat a known plaintext attack. There are, therefore, three keys plus two numerical values in the 0-25 range, for a total key space of size 26!^3*26^2 = 4.4E82, equivalent to 275 binary bits. The name is because it can be most easily implemented using Scrabble tiles placed on either side of a ruler.

## Step 1. Alphabet preparation

We begin by making scrambled alphabets out of the keys. 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 and 2 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 or key 3 boxes empty, key 1 will be used also in those roles. Write a single letter in the key 3 box to turn off transposition.

### Key 3 (transposition)

So here are the initial mixed alphabets produced by processing the keys. If you are using Scrabble tiles, make the first two alphabets on either side of a ruler (I usually put the plaintext alphabet above it and the ciphertext alphabet below it, but this doesn't really matter), with the first letter of each lined up with the zero position:

### Transposition alphabet (might not be full length)

In this implementation, we are using variable positions for the letters that get moved and where they end up. Defaults are for Chaocipher: third letter or position 2 moving to position 13 for plaintext alphabet, second or position 1 moving to position 13 for ciphertext alphabet. Better values are: no move for plaintext alphabet, first letter to position 11 for ciphertext alphabet. We also have the option to cut and swap the halves of each alphabet prior to moving that letter as in Chaocipher, or not do it:

Plaintext letter moved, located at position (0 to 25, default 2, no move if > 25): moved to position (0 to 25, default 13):        Cut     Don't cut

Ciphertext letter moved, located at position (0 to 25, default 1, no move if > 25):  moved to position (0 to 25, default 13):      Cut     Don't cut

Finally, since the processes for encryption and decryption are slightly different, we need 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 is descrambled using the Transposition alphabet as key. This is the result (no change when encrypting):

## Step 3. Encryption / Decryption

It is hard to show how the plaintext and ciphertext alphabets change after every letter encrypted or decrypted, so we'll only show the ciphertext obtained. Do the following to encrypt each plaintext letter:

1. Look it up on the plaintext alphabet (top), then read the letter below it on the ciphertext alphabet. This is the ciphertext letter, which you should write down.
2. Cut the plaintext alphabet after the letter you just looked up, and switch the two parts so that letter now is the last letter.
3. Count a number of letters from the beginning equal to the first number box and take out that letter. Close the gap by joining the two parts that are formed, and insert that letter at the position in the second number box.
4. Now cut the ciphertext alphabet right before the ciphertext letter you just wrote down, and switch the two parts so that letter is now the first.
5. Repeat the instructions in step 3, except that you are modifying the ciphertext alphabet and counting the third number box, and inserting that letter at the location in the fourth number box.

The instructions for decryption are the same, except that you look up the ciphertext letter on the ciphertext alphabet (bottom), in order to obtain the corresponding plaintext letter. Then the alphabets are shuffled after each letter is decrypted exactly as described above. Here's the result of the operation:

## Step 4. Final transposition and result

When encrypting, we do a transposition as final step, using the Transposition alphabet 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. We also perform some statistical tests, which are displayed before the last box.

### Ciphertext / Plaintext

Information about output randomness will appear here