Encryption
Time limit1sMemory limit1024 MB
Given a string encrypted with the rule x -> x^3 mod 29 + 1, recover and print the original symbols.
- Level
Easy3 of 10
- Topics
- Implementation, Math, String, Hash map
- Solved
- No attempts yet
Problem
Ignas and Simonas both became interested in classical cryptography and decided to encrypt text messages to each other. The encryption process they agreed on is as follows.
-
Messages use only the following symbols, numbered from 1 to 29:
- the uppercase Latin letters
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z, numbered from 1 to 26 in alphabetical order; - the underscore
_, used in place of a space — number 27; - the comma
,and the period.— numbers 28 and 29, respectively.
- the uppercase Latin letters
-
The message is encrypted symbol by symbol:
- The symbol's number is cubed, then the remainder of dividing it by 29 is taken, and 1 is added to that remainder.
- Find the new symbol whose number equals the value obtained in step 1. This is the encrypted symbol.
-
Continue in the same way for every symbol of the message.
For convenience, the table of symbol numbers is given below.
For example, the text GERI_ORAI. is encrypted as YJDEVLDBEA by this algorithm. This is easy to check. Take the first letter G:
- the number of the letter
Gis 7, - its cube is ,
- the remainder of dividing 343 by 29 is ,
- adding 1 gives ,
- and the number 25 belongs to the letter
Y.
So, encrypting G gives Y. The encryption of the other symbols can be checked in the same way.
The period ., whose number is 29, is encrypted as the letter A. Since is divisible by 29, the remainder is 0, and adding 1 gives 1, i.e. the letter A.
Ignas's older brother noticed that this encryption algorithm is, unfortunately, very easily "cracked", because the original text can be quickly recovered from the encrypted text, i.e. decrypted.
Write a program that decrypts a line of text encrypted by this algorithm.
Input
The first line contains the encrypted text string.
Output
Print the decrypted text string.