QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#3616. 翻越山丘,第一部分

统计

Hill 加密(由数学家 Lester S. Hill 于 1929 年发明)是一种利用矩阵和模运算的加密技术。它最适用于字符数为质数的字母表,因此我们使用包含 37 个字符的字母表:A, B, ..., Z, 0, 1, ..., 9 以及空格字符。具体步骤如下:

  1. 将初始文本(明文)中的每个字符替换为对应的数值:A $\to 0$, B $\to 1$, ..., (空格) $\to 36$。如果明文是 ATTACK AT DAWN,则转换为: 0 19 19 0 2 10 36 0 19 36 3 0 22 13

  2. 将这些数字分组为三维向量,必要时在末尾补空格。经过此步骤,我们得到: $$ \begin{pmatrix} 0 \\ 19 \\ 19 \end{pmatrix} \begin{pmatrix} 0 \\ 2 \\ 10 \end{pmatrix} \begin{pmatrix} 36 \\ 0 \\ 19 \end{pmatrix} \begin{pmatrix} 36 \\ 3 \\ 0 \end{pmatrix} \begin{pmatrix} 22 \\ 13 \\ 36 \end{pmatrix} $$

  3. 使用模 37 运算,将每个向量乘以预设的 $3 \times 3$ 加密矩阵。如果加密矩阵为: $$ \begin{pmatrix} 30 & 1 & 9 \\ 4 & 23 & 7 \\ 5 & 9 & 13 \end{pmatrix} $$ 那么第一个向量的变换过程如下: $$ \begin{pmatrix} 30 & 1 & 9 \\ 4 & 23 & 7 \\ 5 & 9 & 13 \end{pmatrix} \begin{pmatrix} 0 \\ 19 \\ 19 \end{pmatrix} = \begin{pmatrix} (30 \times 0 + 1 \times 19 + 9 \times 19) \pmod{37} \\ (4 \times 0 + 23 \times 19 + 7 \times 19) \pmod{37} \\ (5 \times 0 + 9 \times 19 + 13 \times 19) \pmod{37} \end{pmatrix} = \begin{pmatrix} 5 \\ 15 \\ 11 \end{pmatrix} $$

  4. 将所有向量与加密矩阵相乘后,将结果值转换回 37 个字符的字母表,并将结果连接起来得到加密后的密文。在我们的示例中,密文为 FPLSFA4SUK2W9K3

该方法可以推广到任意 $n \times n$ 的加密矩阵,此时初始明文被拆分为长度为 $n$ 的向量。对于本题,你将获得一个加密矩阵和一段明文,必须计算出相应的密文。

输入格式

输入的第一行包含一个正整数 $n \le 10$,表示矩阵的大小以及加密所使用的向量长度。接下来有 $n$ 行,每行包含 $n$ 个非负整数,指定了加密矩阵。最后一行包含明文,仅由上述 37 个字符字母表中的字符组成。

输出格式

在一行中输出相应的密文。

样例

样例输入 1

3
30 1 9
4 23 7
5 9 13
ATTACK AT DAWN

样例输出 1

FPLSFA4SUK2W9K3

样例输入 2

6
26 11 23 14 13 16
6 7 32 4 29 29
26 19 30 10 30 11
6 28 23 5 24 23
6 24 1 27 24 20
13 9 32 18 20 18
MY HOVERCRAFT IS FULL OF EELS

样例输出 2

W4QVBO0NJG5 Y76H5A6XHR11BV670Z

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.