# Beaufort cipher

- Description
- Algorithm
- Implementation

This is a simple polyalphabetic cipher, which uses tabula recta (first introduced in the Trithemius cipher). It shouldn't be confused with a variant of a Vigenère cipher named Variant Beaufort.

The Beaufort cipher was used in rotor-based cipher machines Hagelin M-209.

The Beaufort cipher's algorithm is based on tabula recta.

All letters in the plaintext are changed, one by one, according to the table. Both sides share a common secret key, which contains one or more words. Key letters are also taken for encryption one by one. Each key letter are used to encrypt one letter of the message. After the last letter of the key, algorithm goes back to the first letter of the key and continues its work.

The whole process is presented below:

- Find the currently encrypted letter in the top horizontal row.
- Travel down the column until to find the current key letter.
- The leftmost letter in the current row is the new letter of the ciphertext.

Decryption of the ciphertext uses exactly the same algorithm. After the second encryption of ciphertext, one receives the correct plaintext. Ciphers which have the property are referred to as reciprocal ciphers.

Ciphertexts created by the cipher can be very easily changed into ciphertexts of the Vigenère cipher. It can be achieved by changing every letter of the ciphertext to its opposite letter (the letter a becomes z, b becomes y and so on). After this modification, the ciphertext can be analyzed by using all the existing attacks on Vigenère cipher.