QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100 Hackable ✓

#17187. Vigenère 密码

الإحصائيات

题目描述

16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法——Vigenère 密码。Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南北战争中为南军所广泛使用。

在密码学中,我们称需要加密的信息为明文,用 $M$ 表示;称加密后的信息为密文,用 $C$ 表示;而密钥是一种参数,是将明文转换为密文或将密文转换为明文的算法中输入的数据,记为 $k$。在 Vigenère 密码中,密钥 $k$ 是一个字符串,$k=k_1k_2\cdots k_n$。当明文 $M=m_1m_2\cdots m_n$ 时,得到的密文 $C=c_1c_2\cdots c_n$,其中 $c_i=m_i\otimes k_i$,运算的规则如下表所示:

problem_17187_1.png

Vigenère 加密在操作时需注意:

  1. $\otimes$ 运算忽略参与运算的字母的大小写,并保持字母在明文 $M$ 中的大小写形式;
  2. 当明文 $M$ 的长度大于密钥 $k$ 的长度时,将密钥 $k$ 重复使用。

例如,明文 $M=\text{Helloworld}$,密钥 $k=\text{abc}$ 时,密文 $C=\text{Hfnlpyosnd}$。

明文 H e l l o w o r l d
密钥 a b c a b c a b c a
密文 H f n l p y o s n d

输入格式

输入共 $2$ 行。

第一行为一个字符串,表示密钥 $k$,长度不超过 $100$,其中仅包含大小写字母。第二行为一个字符串,表示经过加密后的密文,长度不超过 $1000$,其中仅包含大小写字母。

输出格式

输出共 $1$ 行,一个字符串,表示输入密钥和密文所对应的明文。

样例数据

样例输入

CompleteVictory
Yvqpxaimmklongnzfwpvxmniytm

样例输出

Wherethereisawillthereisaway

子任务

对于 $100\%$ 的数据,输入的密钥的长度不超过 $100$,输入的密文的长度不超过 $1000$,且都仅包含英文字母。

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.