Warning: This statement was translated by an LLM (like ChatGPT). Results might not be fully accurate or faithful to the original statement. Please report any potential errors on our Discord.
Polybius
The Polybius Cipher is a cipher used by the Ancient Greeks, based on a row and column table, to encrypt or decrypt a string of characters. For encryption, we take each character from the string and display the row and column in the table where the character is located. For decryption, we display the character that is located in the table at the given row and column.
For example, using the table:
# | 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 |
Along with the string INF
, we display because the letter I
is located at position , the letter N
is located at position and the letter F
is located at position .
Task
You are given a number , a string of characters , corresponding to the table and a string of characters . You must determine:
- For , encrypt the string , consisting only of uppercase letters, using the table.
- For , decrypt the string , consisting only of digits, using the table.
Input data
The input file polybius.in
contains on the first line the number , on the second line the string consisting of characters, representing all the elements of the table, from left to right and from top to bottom. The third line contains the string of letters that need to be encrypted, if , respectively the string of digits that need to be decrypted, if .
Output data
- For , the output file
polybius.out
will contain on the first line the result of encryption. The digits are displayed without any spaces between them. - For , the output file
polybius.out
will contain on the first line the result of decryption.
Constraints and clarifications
- ;
- the string has a length of characters;
- ;
- It is guaranteed that all characters from are included in the string and the characters from are pairwise distinct.
- There will always be a letter missing from the table, as the table is
5x5
and the alphabet has characters.
Example 1
polybius.in
1
ABCDEFGHIKLMNOPQRSTUVWXYZ
ANAAREMERE
polybius.out
11331111421532154215
Example 2
polybius.in
2
ABCDEFGHIKLMNOPQRSTUVWXYZ
11331111421532154215
polybius.out
ANAAREMERE
Explanation
The table corresponding to the string in the examples is:
# | 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 |