Decipher Neurotic Frogs
Now that Puzzling.SE has finally cracked my amphibian-obsessed cipher, let's write a program or function to decrypt it!
(If you want to look at the puzzle before having it spoiled for you, click the above link now.)
How the cipher works
In Neurotic Frogs Ought To Relax In Mud Baths ("Neurotic Frogs" for short), every letter is encrypted as one or two words:
- The length of a non-italicized word represents a letter.
neurotic
=> 8 letters =>H
frogs
=> 5 letters =>E
perpendicular
=> 13 letters =M
- A word that contains italics modifies the following word, adding 10 if the italicized word was odd in length or 20 if the italicized word was even in length. Any or all of the word may be italicized. An italicized word is always followed by a non-italicized word.
*o*ught to
=> odd, 2 => 12 =>L
lo*u*nging calms
=> even, 5 => 25 =>Y
Every word of plaintext corresponds to a sentence of ciphertext, and every sentence of plaintext corresponds to a paragraph of ciphertext.
Input format
Your program or function shall input a message in Neurotic Frogs, formatted in Markdown. The input will consist only of printable ASCII and newlines.
- Words are runs of characters that match the regex
[A-Za-z0-9']
.- Numbers and letters both count toward the length of a word.
QB64
representsD
. - NOTE: Apostrophes do not count toward the length of a word.
Isn't
representsD
, notE
.
- Numbers and letters both count toward the length of a word.
- Italicized letters are wrapped in a pair of asterisks (
*letters*
).- One or more consecutive letters may be italicized, up to an entire word (
masseus*es*
,*all*
); multiple non-consecutive letters in a word may also be italicized (g*e*n*e*rates
). - Italics never span multiple words, never include punctuation, and never include apostrophes.
- Unpaired asterisks and multiple adjacent asterisks will never occur.
- One or more consecutive letters may be italicized, up to an entire word (
- Punctuation is any of the following characters:
.,?!:;-()"
.- Words within a sentence are separated by one or more punctuation characters and/or a single space. Examples:
*all* welcomed
,toad*s*, newts
,Ever*y*one--frogs
,cap... bliss
,they're (I
- Sentences end with one or more punctuation characters and are separated by a double space:
Th*e* Montgomery A*m*phibian Salon! Come luxuriate today!
- Paragraphs are separated by a single newline. (The last sentence of a paragraph still has one or more punctuation characters at the end.)
- Words within a sentence are separated by one or more punctuation characters and/or a single space. Examples:
Other characters will not appear in input and do not need to be handled.
Your code may, at your discretion, expect input to have a single trailing newline.
Output format
The result of decrypting the input will be one or more sentences. Letters of plaintext may be any combination of upper- and lowercase. Words within a sentence must be separated by single spaces. Sentences must end with a period (.
) and be separated by a single space. You may output a trailing space after the last sentence. Your output will all be on one line, but you may output a trailing newline.
Miscellaneous details
Your code may use any of the standard input and output methods. It must receive input as a multiline string, not a list or other data structure, and it must output a string.
The shortest code in bytes wins!
Test cases
-->
Neurotic Frogs *O*ught To Rel*a*x In *M*ud Baths!
<--
HELLO.
-->
Business standards all*o*w only *adult* amphibians.
<--
HINT.
-->
Rejoice, *a*ll frogs an*d* toads also! Montgomery Sal*o*n opens up! Ha*pp*y throng fill*s* street ecstatically!
<--
GOOD JOB PPL.
-->
I like 3.1415926535897.
IM*O*, it's a *b*la*st*, yeah!
<--
ADAM. MAN.
-->
*I*, happily, *th*anks 2 u *e*ditin*g* specific wor*ding*--clarifying a *bit*--betterment :D!
<--
QUARTATA.
-->
Perpendicular l*ou*nging calms. *A* frog, a m*u*d cap... bliss! Wallowing g*e*n*e*rates happiness. Amphibian sp*a* isn't expensive--seventy d*o*llars--cheap! That'*s* not *a* large e*x*pens*e* from an*y* discerning fr*o*g's money, unlik*e* Super 8.
Ever*y*one--frogs, toad*s*, newts, *a*nd salamanders! G*e*t a wonderful shiat*s*u, or recei*v*e an other kind. Masseus*es* are her*e* today! Invite a fianc*e*e, supervisor, roommate, niece: *all* welcomed!
Y*o*u simply ne*v*er believed these p*o*ssibilitie*s*; they're (I *swear*) absolute truth! Th*e* Montgomery A*m*phibian Salon! Come luxuriate today!
<--
MY NAME IS INIGO MONTOYA. YOU KILLED MY FATHER. PREPARE TO DIE.