/ THO OJ / 题库 /

Vigenère cipher

Vigenère cipher

出题人太菜,暂无测试数据。

Topic Background

The Virginia cipher (also known as the Vigeneˋre cipherVigenère\ cipher) is an encryption algorithm that uses a series of Caesar ciphers to form a cipher alphabet, and belongs to a simple form of multi-table cipher.

The Virginia cipher has been invented several times. The method was first documented in the book The Cipher of Mr. Giovan Battista Bellaso (Italian: La cifra del. Sig. Giovan Battista BellasoLa\ cifra\ del.\ Sig.\ Giovan\ Battista\ Bellaso) by Giovan Battista Bellaso in 1553. However, it was later misrepresented in the 19th century as having been created by the French diplomat Blaise De VigeneˋreBlaise\ De\ Vigenère, and is now known as the Virginia Code.

The Vigenère cipher is known for its simplicity and ease of use, as well as being difficult for beginners to decipher, and is therefore also known as the unbreakable cipher (French: le chiffre indeˊchiffrablele\ chiffre\ indéchiffrable). This has led many people to use the Virginia cipher for encryption purposes just to break it.

Title Description

The Virginia cipher is a key ki(i[1,d])k_i(i \in [1,d]) given by a sequence of dd letters, and kik_i determines the number of shifts for the i+tdi+t_d (tt is an integer) letter.

Modern Virginia cipher substitution table is as follows, the first row of the key, the first column of plaintext, a plaintext corresponding to the key encryption of the resulting ciphertext that is the letter of the row at the column.

Input and output formats

Input format

First line an integer tt, representing the number of operations.

The next 3n3n lines:

Line ii, a string ss consisting of all letters;

Line i+1i + 1 a string of all lowercase letters kk representing the key;

Line i+2i + 2 an integer opop, where opop is 00 for encryption and 11 for decryption.

Output format

A total of nn lines, one string per line, representing the result of the operation.

Sample

Input

2
WhichFruitULike
apple
0
WwxnlFgjtxUAxvi
apple
1

Output

WwxnlFgjtxUAxvi
WhichFruitULike

Sample Explanations

  1. plaintext: s=WhichFruitULikes = \texttt{WhichFruitULike}

    key: k=applek = \texttt{apple}

    First letter plaintext s1=Ws_1 = \texttt{W}, key k1=ak_1 = \texttt{a}, encrypted against the Virginia cipher table the ciphertext is W\texttt{W}.

    \dots

    Sixth letter plaintext s6=Fs_6 = \texttt{F}, key k6k_6 does not exist, so reset key k1=ak_1 = \texttt{a}, encrypted against Virginia cipher table ciphertext is F\texttt{F}.

    \dots

    The fifteenth letter plaintext s15=es_{15} = \texttt{e}, the key k5=ek_5 = \texttt{e}, and the ciphertext encrypted against the Virginia cipher table is i\texttt{i}.

    Therefore, the final encrypted ciphertext is WwxnlFgjtxUAxvi\texttt{WwxnlFgjtxUAxvi}.

  2. ciphertext: s=WwxnlFgjtxUAxvis = \texttt{WwxnlFgjtxUAxvi}.

    Ciphertext: k=applek = \texttt{apple}.

    First letter ciphertext s1=Ws_1 = \texttt{W}, key k1=ak_1 = \texttt{a}, decrypted against the Virginia cipher table the plaintext is W\texttt{W}.

    \dots

    Sixth letter cipher s6=Fs_6 = \texttt{F}, key k6k_6 does not exist, so reset key k1=ak_1 = \texttt{a}, decrypted against the Virginia cipher table the plaintext is F\texttt{F}.

    \dots

    The fifteenth-letter ciphertext s15=es_{15} = \texttt{e}, the key k5=ek_5 = \texttt{e}, and the plaintext decrypted against the Virginia cipher table is i\texttt{i}.

    Therefore, the final decrypted plaintext is WhichFruitULike\texttt{WhichFruitULike}.

Data range

1t1001 \le t \le 100;

1s,k1001 \le |s|, |k| \le 100.

Tip

Virginia cipher table

Virginia cipher table
If you need a Chinese translation, click here.

信息

ID
1010
难度
(无)
分类
模拟 | 字符串 点击显示
标签
(无)
递交数
0
已通过
0
通过率
?
上传者