4
1
The aim is to parse a sentence and compress/encrypt
it according to the rules below and then decrypt
it using the key
:
Remove all letters in a word before the first vowel is encountered. Example:
pigeon
becomesigeon
.All characters except alphabets should be kept in the sentence including numerals, punctuations, etc. Example:
200-storey building
becomes200-orey uilding
.Generate the shortest key array
char[] = {a,b,x,<your data>}
and write code to generate the original sentence using this key.
You need to write two functions: encrypt()
and decrypt()
which works for every sentence minimising the key-size.
Example 1:
Input: The most technologically efficient machine man has ever invented is the book. -Northrop Frye-
Output: e ost echnologically efficient achine an as ever invented is e ook. -orthrop e-
Example key: {T,m,t,m,h,b,N,F,14,2,5}
Example 2:
Input: "I need your clothes, your boots and your motorcycle. " - The T-800 in Terminator 2: Judgment Day
Output: "I eed our othes, our oots and our otorcycle. " - e -800 in erminator 2: udgment ay
Example key: {n,y,c,2,b,2,m,T,J,D,15}
Winning Criteria:
Write function
encrypt()
with input fromstdin
orfile
which generatesoutput
sentence and akey
onstdout
orfile
ormemory
.Write function
decrypt()
with inputs the generated sentence andkey
fromencrypt()
and produces the original sentence.This is
code-golf
so cumulative size of the two functions should be minimum. In case of tie-breaker, the generated key-size should be minimum.
Is there any specific format for the key array? – es1024 – 2014-08-04T06:46:56.623
You can make
key
in any format of your choice, there is no rules for generating thekey
– manav m-n – 2014-08-04T06:57:05.8731In your first example, how does the key restore the 'Fry' of 'Frye'? – trichoplax – 2014-08-04T11:59:01.373
@githubphagocyte the key format and decoding logic entirely depends on you. You can form key in whatever format suitable for accurate decryption. – manav m-n – 2014-08-04T12:15:13.013
missing 'h' in the first example? – edc65 – 2014-08-04T15:47:58.470
Define "vowel". Is
y
a vowel? How aboutü
? Orij
in Dutch texts? Or the Turkish dotless i? – Peter Taylor – 2014-08-05T16:46:37.513