Feature #4: Ways to Decode Message
Implementing the "Ways to Decode Message" feature for our "Cyber Security" project.
We'll cover the following
Description
We are developing a cryptanalysis tool for simple ciphers. Each letter in the alphabet is assigned a specific code in this cipher— for example, 1
for A
, 2
for B
, and so on.
Unfortunately, without additional information, we can’t uniquely decipher some encrypted messages. For example, does the ciphertext 123
represent ABC
(a 1
, followed by a 2
and a 3
), or does it represent AW
(a 1
followed by a 23
) or LC
(a 12
followed by a 3
)? To decipher an encrypted message, all the digits must be grouped and then mapped back into letters, using the reverse of the mapping above (there may be multiple ways of doing this).
We are given a ciphertext, c
, in the form of a string of only digits. Our task is to return the number of possible plain texts.
Note:
c
contains only digits and may contain leading zero(s).
The following examples may clarify these requirements:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.