6 kyu

Bifid cipher

13 of 54JorgeVS

Description:

Bifid Cipher

The Bifid cipher makes use of 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, they shall be removed from the key and from the message.

The square can be changed by using a secret key. If the secret key is "CODEWARS" the grid is adapted by placing the unique letters of the key in front of the alphabet. The key "CODE WARS" gives the same result, because the white space has to be removed. It leads to the following square.

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

To encode a message the coordinates of each letter are written in a column below the corresponding letter.

With key "CODEWARS" the message "WARRIOR" is written down as follows:

Message: WARRIOR
Row:     1222312
Column:  5122322

The encoding takes place by reading horizontally and finding the corresponding letters.

12 22 31 25 12 23 22 -> ORGFOSR

Of course the decoding is done reversely.

Only capital letters and white spaces are used.

Your challenge is to write two functions encodeBifid and decodeBifid.

Fundamentals

More By Author:

Check out these other kata created by JorgeVS

Stats:

CreatedJan 24, 2019
PublishedJan 24, 2019
Warriors Trained187
Total Skips12
Total Code Submissions571
Total Times Completed54
Haskell Completions13
Java Completions44
Total Stars10
% of votes with a positive feedback rating92% of 19
Total "Very Satisfied" Votes17
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • JorgeVS Avatar
  • JohanWiltink Avatar
  • Voile Avatar
Ad