QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 2048 MB Puntuación total: 100

#1300. 窃密术

Estadísticas

John 喜欢简单的密码。直到最近,他一直使用“凯撒”密码来加密他的日记,直到他发现他的妹妹 Mary 可以毫无困难地浏览他的日记,从而深刻地认识到了这种密码的脆弱性。

为了寻找替代方案,John 很快找到了一个解决方案:著名的“自动密钥”(Autokey)密码。他使用的版本采用 26 个小写字母 'a'–'z',并在内部将它们按字母顺序转换为 0 到 25 的数字。

加密密钥 $k$ 以一个 $n$ 个字母的秘密前缀开头。密钥的其余每个字母都从明文 $a$ 的字母中复制而来,即对于 $i \ge 1$,有 $k_{n+i} = a_i$。明文 $a$ 到密文 $b$ 的加密遵循公式 $b_i = a_i + k_i \pmod{26}$。

Mary 并没有轻易放弃。在 John 发现她之前,她设法瞥见了 John 在家用电脑上输入到日记中的最后 $n$ 个字母,随后 John 点击鼠标快速加密了文本文档并离开了。这可能是她的机会。

输入格式

输入包含: 一行,包含两个整数 $n$ 和 $m$ ($1 \le n \le 30, n + 1 \le m \le 100$),其中 $n$ 是关键字的长度,也是 Mary 看到的字母数量,$m$ 是文本的长度。 一行,包含 $n$ 个小写字母,即明文的最后 $n$ 个字母。 * 一行,包含 $m$ 个小写字母,即完整的密文。

输出格式

输出 John 日记的明文。

样例

样例输入 1

5 16
again
pirpumsemoystoal

样例输出 1

marywasnosyagain

样例输入 2

1 12
d
fzvfkdocukfu

样例输出 2

shortkeyword

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.