Decode a message using the Polybius square
Description:
The ancient Greek historian and scholar Polybius was the inventor of an early cryptographic technique: the Polybius square. Using the Polybius square, a message written using alphanumeric characters could be represented using a smaller set of symbols. In this case, the symbols are the numbers 1-6.
The typical form of the Polybius square that includes the letters A-Z and the numbers 0-9 is:
1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|
1 | A | B | C | D | E | F |
2 | G | H | I | J | K | L |
3 | M | N | O | P | Q | R |
4 | S | T | U | V | W | X |
5 | Y | Z | 0 | 1 | 2 | 3 |
6 | 4 | 5 | 6 | 7 | 8 | 9 |
Using the Polybius square, the letter 'A' would be represented as '11', the letter 'B' as '12', and so on. Polybius designed this cipher to be used in fire signalling rather than to encrypt secret messages; indeed, once you know the technique it is trivial to decode any message.
A progression has therefore been to shift the symbols in the table by a pre-arranged number, as is done in a Caesar's cipher. The Polybius square with a shift of 16 places would be:
1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|
1 | U | V | W | X | Y | Z |
2 | 0 | 1 | 2 | 3 | 4 | 5 |
3 | 6 | 7 | 8 | 9 | A | B |
4 | C | D | E | F | G | H |
5 | I | J | K | L | M | N |
6 | O | P | Q | R | S | T |
Your task is to build an algorithm that will, given a message encoded with a shifted Polybius square and the value of the shift, decode the message into plaintext.
Some things to note:
- the ciphertext will be provided in the format XX.XX.XX XX.XX, where 'XX' corresponds to a character, a period separates each character, and a space separates each word
- if the ciphertext contains anything but numbers, periods and spaces, return
null
- ignore any leading periods, and ignore consecutive periods between characters
- if no ciphertext is passed in, return an empty string
- if an illegal number (e.g 1, 17, 100, etc.) appears in the ciphertext, return
null
- if the shift is not an integer between 0 and 35, return
null
- the plaintext message should be returned in upper case and include any and all spaces in the ciphertext
Similar Kata:
Stats:
Created | Apr 5, 2018 |
Published | Apr 8, 2018 |
Warriors Trained | 132 |
Total Skips | 0 |
Total Code Submissions | 201 |
Total Times Completed | 13 |
JavaScript Completions | 13 |
Total Stars | 3 |
% of votes with a positive feedback rating | 83% of 6 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 8 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |