The Bifid cipher, invented by the French amateur cryptographer Félix Delastelle around 1901, is a fractionating transposition cipher.
The Bifid cipher uses a 5 x 5 Polybius square.
The letters of a message are encoded via the coordinates of that letter in the square.
1 2 3 4 5 1 A B C D E 2 F G H I K 3 L M N O P 4 Q R S T U 5 V W X Y Z
- In the square all the letters of the alphabet except 'J' are present.
- Each letter appears only one time.- Each 'J' in input must be changed to 'I'.
- White spaces are ignored and shall be removed from the key and from the message.
Example:
Let's say we want to encode "Hello World" with the key "Sololearn"
Then the Polybius square can be written as below
1 2 3 4 5 1 S O L E A 2 R N B C D 3 F G H I K 4 M P Q T U 5 V W X Y Z
[ Notice : The head of the square is formed by the key and all the duplicate letters, 'J' and whitespace are ignored. ]
To encode the message we need to find the coordinates of each letter in the Polybius square.
For example the first letter of our msg, "H" can be found in Row : 3 and Col : 3.
The full message "HELLOWORLD" can be written down as follows:
Msg: HELLOWORLD
Row: 3 1 1 1 1 5 1 2 1 2
Col : 3 4 3 3 2 2 2 1 3 5
The encoding takes place by merging the values of rows and columns.
Row values followed by the column values.
And then we read them horizontally and find the corresponding letters from our Polybius square.
31 11 15 12 12 34 33 22 21 35 --> F S A O O I H N R K
Output should be in uppercase with no whitespace.