Decode the Message
You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:
- Use the first appearance of all 26 lowercase English letters in
keyas the order of the substitution table. - Align the substitution table with the regular English alphabet.
- Each letter in
messageis then substituted using the table. - Spaces
' 'are transformed to themselves.
Return the decoded message.
Example 1
Input
key = "the quick brown fox jumps over the lazy dog", message = "vkbs bs t suepuv"Output
"this is a secret"The substitution table is obtained by taking the first appearance of each letter in
key, which decodes the message to this is a secret.Example 2
Input
key = "eljuxhpwnyrdgtqkviszcfmabo", message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"Output
"the five boxing wizards jump quickly"The substitution table is obtained by taking the first appearance of each letter in
key, which decodes the message to the five boxing wizards jump quickly.Constraints
- 26 <= key.length <= 2000
- key consists of lowercase English letters and ' '.
- key contains every letter in the English alphabet ('a' to 'z') at least once.
- 1 <= message.length <= 2000
- message consists of lowercase English letters and ' '.