# For The Love of Ciphers: Félix-Marie Delastelle

## Two-square, three-square and four-square

The French cryptographer Félix-Marie Delastelle was born in 1850 and died in 1902. For most of his life he worked as a bonded warehouseman at a local port. After his retirement in 1900, he published a 50-page book named Traité Élémentaire de Cryptographie. His love of creating ciphers was basically his hobby, and he was unusual as most of the people who worked in the field at the time were either academics, diplomats, or in the military.

His core contribution includes fractionation and transposition, and from these he created the Bifid cipher (created with two squares), the Trifid cipher (created with three square) and the Four Square cipher. These types of ciphers are generally known as polygraphic substitution ciphers, and where two or more letters are taken at a time, and then ciphered.

## Four square cipher

The four-square cipher uses four squares, and where we take pairs of letters and, using the first and last square, we find the letters that are bounded by the two letters (like Playfair). It was invented by Félix Delastelle and published in 1902.

It uses four 5x5 matrices arranged in a square. Each matrix contains 25 letters. The upper-left and lower-right matrices are the “plaintext squares” and each contain a standard alphabet. The upper-right and lower-left squares are the “ciphertext squares” and have a mixture of characters.

First we break the message into bi-grams, such as ATTACK AT DAWN gives:

AT TA CK AT DA WN

We now uses the four ‘squares’ and locate the bigram to encrypt in the plain alphabet squares. With ‘AT’, we take the first letter from the top left square, the the second letter from the bottom right square:

    a b c d e   Z G P T F    f g h i k   O I H M U    l m n o p   W D R C N    q r s t u   Y K E Q A    v w x y z   X V S B L         M F N B D   a b c d e    C R H S A   f g h i k    X Y O G V   l m n o p    I T U E W   q r s t u    L Q Z K P   v w x y z

Now, like Playfair, determine the the characters in the ciphertext around the corners of the rectangle for ‘AT’ and this makes:

    a b c d e   Z G P T F    f g h i k   O I H M U    l m n o p   W D R C N    q r s t u   Y K E Q A    v w x y z   X V S B L         M F N B D   a b c d e    C R H S A   f g h i k    X Y O G V   l m n o p    I T U E W   q r s t u    L Q Z K P   v w x y z

And so we pick off ‘TI’

The result becomes:

    ATTACKATDAWN    TIYBFHTIZBSY

The following is an outline of the code which would implement this:

import sysfrom pycipher import Foursquarefour1='ZGPTFOIHMUWDRCNYKEQAXVSBL'four2='MFNBDCRHSAXYOGVITUEWLQZKP'phrase='ATTACK AT DAWN'if (len(sys.argv)>1):        four1=str(sys.argv)if (len(sys.argv)>2):        four2=str(sys.argv)if (len(sys.argv)>3):        phrase=str(sys.argv)from pycipher import Foursquares = Foursquare(four1,four2)res=Foursquare(key1=four1,key2=four2).encipher(phrase)print "Cipher: ",resprint "Decipher: ",Foursquare(key1=four1,key2=four2).decipher(res)

Here are two examples:

• ATTACKATDAWN and “ZGPTFOIHMUW DRCNYKEQAXVSBL” and “MFNBDCRHSAXY OGVITUEWLQZKP” should give TIYBFHTIZBSY. Try!
• “Defend the east wall of the castle” and “ZGPTFOIHMUWDRC NYKEQAXVSBL” and “MFNBDCRHSAXY OGVITUEWLQZKP” should give FBUMCNESFDPI KKZXCXMIUNZNQUNM. Try!

## Bifid cipher

In Morse Code we have the problem of coding with varying lengths of encoded characters (the dots and dashes), where we must put a space (or pause) in-between. To overcome this we can use a fractionating cipher, where we convert our encoded characters into three character sequences. For example “Hello World” in Morse Code becomes:

.... . .-.. .-.. --- /      .-- --- .-. .-.. -..H    E   L    L   O  SPACE    W  O   R   L    D

We can then make this into a string with an ‘x’ between characters:

Plain text:    H    e l    l    o    w   o   r   l    dMorse string:  ....x.x.-..x.-..x---xx.--x---x.-.x.-..x-..

We can now use three-character mappings to convert them back to text:

['...', '..-', '..x', '.-.', '.--', '.-x', '.x.', '.x-', '.xx', '-..', '-.-', '-.x', '--.', '---', '--x', '-x.', '-x-','-xx', 'x..', 'x.-', 'x.x', 'x-.', 'x--', 'x-x', 'xx.', 'xx-']

This mapping is:

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. . . . . . . . . - - - - - - - - - x x x x x x x x. . . - - - x x x . . . - - - x x x . . . - - - x x. - x . - x . - x . - x . - x . - x . - x . - x . -

which will map to “ABCDEF…Z”. Next we can convert them back with:

AGTCDHOTQODTCJ

For “Peter piper picked “ we get:

.--.x.x-x.x.-.xx.--.x..x.--.x.x.-.xx.--.x..x-.-.x-.-x.x-..xxP    e t e r ' ' p    i   p  e  r' ' p    i  c    k  e  d ' '

If you are interested, here are the Morse Code mappings;

E .   S ...  H ....  B -...  1 .----  period  .-.-.-T -   U ..-  V ...-  X-..-   2 ..---  comma   --..--I ..  R .-.  F ..-.  C-.-.   3 ...--  query   .-.-.-A .-  W .--  L .-..  Y --.-  4 ....-  colon   ---...N -.  D -..  P .--.  Z --..  5 .....  s/colon -.-.-.M --  K -.-  J .---  Q --.-  6 -....  dash    -....-      G --.                  7 --...  slash   -..-.      O ---                  8 ---..  equals  -...-                             9 ----.                             0 -----

Felix Delastelle, in 1895, saw the potential of this method and then used it to create a bifid cipher which uses fractionation and transposition, and where we take a key and then translate it into three squares.

An example key is:

EPSDUCVWYM.ZLKXNBTFGORIJHAQ

We then make three squares from this:

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

If we take a plain text message of “THIS IS A TEST”, we locate the text in the squares defined above:

THIS IS A TEST--------------T - 233H - 331I - 322S - 113I - 322S - 113A - 332T - 233E - 111S - 113T - 233

Next we would order as:

THISISATEST-----------233331322113322113332233111113233

And we would read the code in a horizontal way to give:

233 333 321 321 311 111 331 233 232 123 123

And then substitute back the letters on the grid:

233 333 321 321 311 111 331 233 232 123 123T   Q   R   R   F   E   H   T   B   C   C

If you understand this, why not try your skills here?

And if you really want a challenge, try to crack the following fractionated ciphers here.

## Trifid cipher (Three square)

The Delastelle cipher (or Trifid cipher) uses substitution with transposition and fractionation. An example key is:

EPSDUCVWYM.ZLKXNBTFGORIJHAQ

We then make three squares from this:

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

If we take a plain text message of “THIS IS A TEST”, we locate the text in the squares defined above:

THIS IS A TEST--------------T - 233H - 331I - 322S - 113I - 322S - 113A - 332T - 233E - 111S - 113T - 233

Next we would order as:

THISISATEST-----------233331322113322113332233111113233

And we would read the code in a horizontal way to give:

233 333 321 321 311 111 331 233 232 123 123

And then substitute back the letters on the grid:

233 333 321 321 311 111 331 233 232 123 123T   Q   R   R   F   E   H   T   B   C   C

Try this example: [here]

Try an example:

• DEFEND THE EAST WALL OF THE CASTLE. Try!
• THIS IS A TEST Try!
• TREATYENDSBOERWAR (key=FRYJXBOCSVGMZDWLPTEN.UHKQAI). Try!

## Conclusions

Go and exercise your brain, and learn some ciphers …

Written by