In Ragbaby Cipher, encoding is done by a string of keys and their position in the plaintext word of a message.
Create a function that takes two arguments, key and message, and returns the encoded message.
There are some variations on the rules of encipherment. One version of the cipher rules are outlined below:
message = "This is an example."
key = "cipher"
ragbaby_cipher(message, key) ➞ "Urew pu bq rzfsbtj."
Step 1: Remove duplicate alphabets of the key. Rearrange alphabets from A-Z, such that the keyword appears first, followed by the rest of the alphabets in the usual order.
c i p h e r a b d f g j k l m n o q s t u v w x y z
Step 2: Word-by-word, assign numbers to the letters of the given message:
T h i s i s a n e x a m p l e .
1 2 3 4 1 2 1 2 1 2 3 4 5 6 7
Step 3: Replace each alphabet of the word with the letter in the keyed alphabet the corresponding number of places to the right of it (wrapping if necessary). Keep all characters other than alphabets in the same order and without any change.
eMessage = "Urew pu bq rzfsbtj."
# 'u' is 1 place right to 't'
# 'r' is 2 places right to 'h'
# 'e' is 3 places right to 'i' and so on.
# keep the '.' in the same position.
See the below examples for a better understanding:
ragbaby_cipher("This is an example.", "cipher") ➞ "Urew pu bq rzfsbtj."
ragbaby_cipher("mubashir", "innokodakademija") ➞ "nwccyoke"
ragbaby_cipher("mattttt", "eedddabit") ➞ "nighjkl"