How to resolve the algorithm Bifid cipher step by step in the Ada programming language
How to resolve the algorithm Bifid cipher step by step in the Ada programming language
Table of Contents
Problem Statement
The Bifid cipher is a polygraphic substitution cipher which was invented by Félix Delastelle in around 1901. It uses a 5 x 5 Polybius square combined with transposition and fractionation to encrypt a message. Any 5 x 5 Polybius square can be used but, as it only has 25 cells and there are 26 letters of the (English) alphabet, one cell needs to represent two letters - I and J being a common choice. Suppose we want to encrypt the message "ATTACKATDAWN". We use this archetypal Polybius square where I and J share the same position. The message is first converted to its x, y coordinates, but they are written vertically beneath. They are then arranged in a row. Finally, they are divided up into pairs which are used to look up the encrypted letters in the square. The encrypted message is therefore "DQBDAXDQPDQH". Decryption can be achieved by simply reversing these steps. Write routines in your language to encrypt and descrypt a message using the Bifid cipher. Use them to verify (including subsequent decryption):
- The above example.
- The example in the Wikipedia article using the message and Polybius square therein.
- The above example but using the Polybius square in the Wikipedia article to illustrate that it doesn't matter which square you use as long, of course, as the same one is used for both encryption and decryption. In addition, encrypt and decrypt the message "The invasion will start on the first of January" using any Polybius square you like. Convert the message to upper case and ignore spaces. Suggest a way in which the cipher could be modified so that ALL 26 letters can be uniquely encrypted. Playfair cipher
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bifid cipher step by step in the Ada programming language
Source code in the ada programming language
-- Bifid cipher
-- J. Carter 2023 May
-- The Bifid cipher is included as part of the PragmAda Reusable Components (https://github.com/jrcarter/PragmARC)
with Ada.Text_IO;
with PragmARC.Encryption.Bifid;
procedure Bifid_Test is
package Bifid renames PragmARC.Encryption.Bifid;
Key_1 : constant Bifid.Square_Layout := ("ABCDE", "FGHIK", "LMNOP", "QRSTU", "VWXYZ");
Key_2 : constant Bifid.Square_Layout := ("BGWKZ", "QPNDS", "IOAXE", "FCLUM", "THYVR");
Msg_1 : constant String := "ATTACKATDAWN";
Msg_2 : constant String := "FLEEATONCE";
Msg_3 : constant String := "THEINVASIONWILLSTARTONTHEFIRSTOFJANUARY";
Crypt_1 : String (Msg_1'Range);
Crypt_2 : String (Msg_2'Range);
Crypt_3 : String (Msg_3'Range);
begin -- Bifid_Test
Crypt_1 := Bifid.Encrypt (Msg_1, Key_1);
Ada.Text_IO.Put_Line (Item => Msg_1 & " => " & Crypt_1 & " => " & Bifid.Decrypt (Crypt_1, Key_1) );
Crypt_2 := Bifid.Encrypt (Msg_2, Key_2);
Ada.Text_IO.Put_Line (Item => Msg_2 & " => " & Crypt_2 & " => " & Bifid.Decrypt (Crypt_2, Key_2) );
Crypt_1 := Bifid.Encrypt (Msg_1, Key_2);
Ada.Text_IO.Put_Line (Item => Msg_1 & " => " & Crypt_1 & " => " & Bifid.Decrypt (Crypt_1, Key_2) );
Crypt_3 := Bifid.Encrypt (Msg_3, Key_2);
Ada.Text_IO.Put_Line (Item => Msg_3 & " => " & Crypt_3 & " => " & Bifid.Decrypt (Crypt_3, Key_2) );
end Bifid_Test;
You may also check:How to resolve the algorithm Long year step by step in the PHP programming language
You may also check:How to resolve the algorithm First-class functions step by step in the C# programming language
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the NewLISP programming language
You may also check:How to resolve the algorithm Arithmetic-geometric mean step by step in the Potion programming language