Four-square cipher is a symmetric encryption technique. It was invented by the famous French cryptographer Felix Delastelle.
The technique encrypts pairs of letters (double characters) and thus falls under the category of ciphers known as polygraphic replacement ciphers. This adds significant power to the encryption compared to monographic substitution codes which operate on single characters. The use of digraphs makes the four-square technique less susceptible to frequency analysis attacks, as the analysis should be performed on 676 possible digraphs, not just 26 for monographic substitution. Frequency analysis of two characters is possible, but much more difficult - and generally requires much larger cipher text to be useful.
Four-square cipher was used on all fronts during World War II by all parties to the conflict. Currently, it is considered obsolete, mainly due to effective and quick brute force attacks that can be carried out with computers.
Four-square cipher consists of a code table containing four code squares (matrices) with 5x5 fields. Each square is filled with 25 letters of the Latin alphabet. Due to the fact that the Latin alphabet contains 26 letters, one letter that is least used in the alphabet is removed or the letters are used alternatively (eg I instead of J). The upper left square and lower right contain letters sorted alphabetically from A-Z. However, the lower left and upper right square are filled with letters containing the key without repeating the letters.
For example, by setting the key to the upper right matrix PTERWSZY and the lower left DRUGI and replacing J with I our code table will look like this:
a b c d e P I E R W
f g h i k S Z Y A B
l m n o p C D F G H
q r s t u K L M N O
v w x y z Q T U V X
D R U G I a b c d e
A B C E F f g h i k
H K L M N l m n o p
O P Q S T q r s t u
V W X Y Z v w x y z
To encrypt the plaintext, we break it into two characters of pairs of letters. If the explicit word does not have an even number of letters then at the end we add the letter X. For example, if we want to encode the word CALCOOLATOR we divide it into pairs CA LC OO LA TO RX . At the end of the word we added X because the number of letters was odd. Our encoder will automatically add the letter X if the plaintext contains an odd number of letters.
Then we find the first letter of the pair C in the upper left square and the second letter A in the lower right square.
a b c d e P I E R W
f g h i k S Z Y A B
l m n o p C D F G H
q r s t u K L M N O
v w x y z Q T U V X
D R U G I a b c d e
A B C E F f g h i k
H K L M N l m n o p
O P Q S T q r s t u
V W X Y Z v w x y z
Now we read the letters from the intersection points first in the upper right square and then in the lower left square.
a b c d e P I E R W
f g h i k S Z Y A B
l m n o p C D F G H
q r s t u K L M N O
v w x y z Q T U V X
D R U G I a b c d e
A B C E F f g h i k
H K L M N l m n o p
O P Q S T q r s t u
V W X Y Z v w x y z
The first encoded letter pair of the clear word CA will be PU . We repeat the reading operation for each of the pairs of letters of the clear word CA LC OO LA TO RX and assign it pairs read from the code table PU FD GM CD NM MW.
More on: Wikipedia - Trifid cipher