#B2116. Decrypt Encrypted Patient Names
Decrypt Encrypted Patient Names
Decrypt Encrypted Patient Names
During a hospital pharmacy internship, Xiao Ying was given a challenging task to decrypt patient names that were encrypted during the wartime era. The encryption was applied with three operations on the original string:
- Cyclically shift each letter 3 positions to the left in the alphabet (with wrapping). For example, in lowercase:
b
becomesy
,c
becomesz
, andd
becomesa
. - Reverse the entire string.
- Invert the case of each letter (i.e. uppercase letters become lowercase and vice versa).
Your task is to decrypt a given encrypted string. To do so, you must reverse the encryption steps. Note that both uppercase and lowercase letters are processed separately according to their own alphabet.
The decryption process is as follows:
- Step 1: Invert the case of each character in the encrypted string.
- Step 2: Reverse the string obtained from Step 1.
- Step 3: For each letter in the resulting string, shift it 3 positions to the right in the alphabet (using modulo arithmetic) to recover the original letter. Use the formula:
\(\text{original} = \text{chr}(((\text{ord}(c) - \text{ord}('A' or 'a') + 3) \mod 26) + \text{ord}('A' or 'a'))\) for uppercase and lowercase respectively.
inputFormat
A single line containing the encrypted string. The string consists only of alphabetic characters.
outputFormat
Output the decrypted string.
sample
AZY
bcd