Rövarspråket (English: The Robber Language) is a Swedish language game. It became popular after the books about Kalle Blomkvist by Astrid Lindgren, where the children use it as a code, both at play and in solving actual crimes.
The principle is easy enough. Every group of successive consonants is doubled, and the letter o is inserted in between the two repetitions of the group. In case a group of successive consonants contains uppercase letters, they are converted into their corresponding lowercase variants in the second repetition of the group. All vowels and non-letter characters are left intact.
For example, consider the term robber language, where we have underlined the six groups of successive consonants. If we convert this term into Rövarspråket, we get
rorobbobberor lolangonguagoge
where we have underlined the groups of successive consonants once more. Needless to say, the code is not very useful in written form, but it can be tough when spoken by a trained (and thus quick) user. On the other hand, for an untrained speaker, a word or phrase can often be something of a tongue-twister1 or a shibboleth2.
Today, the books of Astrid Lindgren — and the subsequent films — are so well known in Sweden and Norway, that the language has become integrated in the culture of schoolchildren. Most Scandinavians are familiar with it.
We define the vowels as the letters a, e, i, o and u. All other letters of the alphabet are considered to be consonants, including the letter y which sometimes is considered to be a vowel in the English language. Your task:
Write a function encode that takes an English sentence (str) and returns its translation into Rövarspråket (str).
Write a function decode that takes a sentence in Rövarspråket (str) and return its translation into plain English (str).
>>> encode('robber language')
'rorobbobberor lolangonguagoge'
>>> encode('Kalle Blomkvist')
'Kokallolle Bloblomkvomkvistost'
>>> encode('Astrid Lindgren')
'Astrostridod Lolindgrondgrenon'
>>> decode('rorobbobberor lolangonguagoge')
'robber language'
>>> decode('Kokallolle Bloblomkvomkvistost')
'Kalle Blomkvist'
>>> decode('Astrostridod Lolindgrondgrenon')
'Astrid Lindgren'
This shows how the text fragment Kalle Blomkvist can be translated into Rövarspråket.
This shows how the translation of the text fragment Kalle Blomkvist into Rövarspråket can be converted back into plain English.