Alternative Encryption
Time limit2sMemory limit1024 MB
Given strings of lowercase letters, encrypt or decrypt each one so that the output keeps its length, and each letter differs from the original at the same position.
- Level
Medium4 of 10
- Topics
- String, Math, Implementation
- Solved
- No attempts yet
Problem
TU Delft has decided to implement a system of secure communication, called New Well-Encrypted Remote Communication, to fight the theft of intellectual property by rival universities. All internal communication will be encrypted before it is sent over the network and decrypted on arrival. The infrastructure is already set up, and TU Delft has asked you to design the encryption.
You must design an algorithm that both encrypts and decrypts text made of only English lowercase letters. You do not need to explain how it works, and TU Delft wants it kept secret to improve security. The algorithm must meet these criteria:
- No matter what the text is, encrypting it and then decrypting the result yields the original text.
- The encrypted text consists of only English lowercase letters and has the same number of letters as the original text.
- For all , the th letter of the encrypted text differs from the th letter of the original text.
The word nwercjury may not be encrypted as irritating, because the lengths differ. It also may not be encrypted as imbecilic, because the fifth letter is c in both. An acceptable encryption is fantastic, which has an n and a c like the original, but in different positions.
Your program runs twice for each test case. In the first run, it receives strings to encrypt. In the second run, it receives the encrypted strings and must decrypt them to recover the originals.
A testing tool is provided to help you develop your solution.
Input
The input consists of:
- One line with either
encryptordecrypt, indicating the action your program has to perform. - One line with an integer (), the number of strings.
- lines, each with a string (), the text to encrypt or decrypt. All input strings consist of only English lowercase letters (
a-z).
Output
For each string, output its encryption or decryption, as required.