#P2636. Japanese Encryption Techniques

    ID: 15903 Type: Default 1000ms 256MiB

Japanese Encryption Techniques

Japanese Encryption Techniques

During World War II, Japanese forces used various encryption methods to secure their communications. In this problem, you are asked to implement one of the following three encryption schemes:

  • 1. Fence Cipher: Divide the plaintext into groups of L characters. Then, form the ciphertext by concatenating the first character of each group, then the second character of each group, and so on. If the last group is shorter than L, only available characters are used.
  • 2. Vigenère Cipher: Given a plaintext M and a key k, encrypt each character using the formula $$ c_i = (m_i + (k_i - A)) \mod 26 $$ where the key is repeated if M is longer than k. Letters maintain their original case.
  • 3. QWE Keyboard Cipher: Using the following keyboard layout:
        QWERTYUIOP
        ASDFGHJKL
        ZXCVBNM
        
    create a mapping by reading the keys in order to form the string "QWERTYUIOPASDFGHJKLZXCVBNM". Then, replace each letter in the plaintext as follows: A is replaced by Q, B by W, C by E, …, Z by M.

The input begins with an integer indicating which encryption method to use:

  • If the integer is 1, the next line contains an integer L (the number of columns) and the following line contains the plaintext (without spaces).
  • If the integer is 2, the next two lines contain the plaintext and key, respectively.
  • If the integer is 3, the next line contains the plaintext.

Your task is to output the encrypted string based on the selected encryption method.

inputFormat

The first line contains an integer T (1, 2, or 3) indicating the encryption method. Depending on T:

  • If T = 1: The second line contains an integer L, and the third line contains the plaintext (without spaces).
  • If T = 2: The second line contains the plaintext, and the third line contains the key.
  • If T = 3: The second line contains the plaintext.

outputFormat

Output the encrypted string according to the selected encryption method.

sample

1
2
THEREISACIPHER
TEESCPEHRIAIHR