Decode the message
Statement
Goal
As an FBI agent you intercepted a message from terrorists.This message has to be decrypted, and to do so you have access to 2 pieces of information : P and C.
C is the alphabet used to write the message, and contains all the letters/characters needed to decode it.
P corresponds to the encoded value of the message.
Thankfully, you happen to know how this value is computed, and now need to reverse the following process :
- Assuming the alphabet is 'abcd', each letter is associated to its index : a = 0, b = 1, c = 2, d = 3.
- For the following values, a new letter is either added or switched :
- aa = 4, ba = 5, ca = 6, da = 7
- ab = 8, bb = 9, cb = 10, db = 11
- ...
- aaa = 20, baa = 21, caa = 22, daa = 23, and so on.
- The whole message gets a unique value this way. For example with a full alphabet (26 letters) 'hello' would be 7073801.
Get it done agent ! (Good Luck)
Input
first line : an integer P, the encoded value of the message.
second line : a string C, the alphabet used for the message. Every character in the string is unique, and a space can be one of them.
second line : a string C, the alphabet used for the message. Every character in the string is unique, and a space can be one of them.
Output
One line containing the decoded message.
Constraints
0 < P < 10^16
Example
Input
35 abcdefghijklmnopqrstuvwxyz
Output
ja
Tags
Cryptography, Encoding, Modular calculus
Difficulty
Easy
Test cases
Test 1 Test
Input
35
abcdefghijklmnopqrstuvwxyz
Output
ja
Validator 1 Validator
Input
42
abcdefghijklmnopqrstuvwxyz
Output
qa
Test 2 Test
Input
13484
abcdefghijklmnopqrstuvwxyz
Output
qxs
Validator 2 Validator
Input
15627
abcdefghijklmnopqrstuvwxyz
Output
bcw
Test 3 Test
Input
132
ABeDFC
Output
ADe
Validator 3 Validator
Input
137
ABeDFC
Output
CDe
Test 4 Test
Input
124
0123456789
Output
410
Validator 4 Validator
Input
117
1234567890
Output
811
Test 5 Test
Input
155675
0123456789
Output
565440
Validator 5 Validator
Input
167863
0123456789
Output
357650
Test 6 Test
Input
34170657950616
H_eo: Wrld!
Output
Hello ! World
Validator 6 Validator
Input
21098561032417
Heol_! Wrd:
Output
Hello World !
Test 7 Test
Input
2060735972420674
abcdefghijklmnopqrstuvwxyz !ABCDEFGHIJKLMNOPQRSTUVWXYZ
Output
Awesome !
Validator 7 Validator
Input
379296528450479
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ!
Output
! Awesome
Solution language
Solution
Stub generator input