#P1703. 那个什么密码 2
那个什么密码 2
Description
In the 16th century, the French diplomat Blaise de Vigenère designed a polyalphabetic cipher called the Vigenère cipher. The Vigenère cipher is simple and easy to use for both encryption and decryption, yet relatively hard to crack. It was widely used by the Confederate Army during the American Civil War.
In cryptography, the information to be encrypted is called the plaintext, denoted by ; the encrypted information is called the ciphertext, denoted by ; and the key is a parameter used as input to the algorithm that converts plaintext to ciphertext or ciphertext to plaintext, denoted by . In the Vigenère cipher, the key is a string of letters, . When the plaintext is , the ciphertext obtained is , where . The rules for the operation are shown in the table below:

Notes when applying Vigenère encryption:
- The operation ignores the case of the letters involved, and preserves the letter case as it appears in the plaintext .
- When the length of the plaintext is greater than the length of the key , repeat the key .
Task: Given a plaintext and a key, perform two rounds of encryption:
- First-stage encryption: sequentially apply instructions of the form , reversing the characters from the -th to the -th positions of the plaintext.
- Second-stage encryption: according to the above rules, apply the Vigenère cipher once more to the result of the first stage to obtain the final level-2 ciphertext.
For example, with plaintext , key , , and instruction , the level-1 ciphertext is , and the level-2 ciphertext is .
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|c|c|c|c|c|} \hline \textsf{Plaintext} & \tt H & \tt e & \tt l & \tt l & \tt o & \tt w & \tt o & \tt r & \tt l & \tt d \\ \hline \textsf{Level-1 Ciphertext} & \tt H & \tt e & \tt l & \tt l & \tt r & \tt o & \tt w & \tt o & \tt l & \tt d \\ \hline \textsf{Key} & \tt a & \tt b & \tt c & \tt a & \tt b & \tt c & \tt a & \tt b & \tt c & \tt a \\ \hline \textsf{Level-2 Ciphertext} & \tt H & \tt f & \tt n & \tt l & \tt s & \tt q & \tt w & \tt p & \tt n & \tt d \\ \hline \end{array}$$Input Format
The first line contains a string representing the key , with length not exceeding 1000, containing only uppercase and lowercase letters.
The second line contains a string representing the plaintext before encryption, with length not exceeding 1000, containing only uppercase and lowercase letters.
The third line contains a non-negative integer (), representing the number of instructions in the first-stage encryption.
Each of the following lines contains two positive integers (), representing one instruction, where is the length of the plaintext.
Output Format
Output a single string, which is the level-2 ciphertext corresponding to the given key and plaintext.
CompleteVictory
Wherethereisawillthereisaway
0
Yvqgpxaimmklongnzfwpvxmniytm
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号