2
\$\begingroup\$

This question already has an answer here:

Write a program or function that will break ciphers, using as few bytes as possible.

Task

Given an encrypted message and a dictionary as input, output the decrypted message. The messages will be encrypted using a one-to-one character mapping, i.e. two characters can't both map to one, and vice versa. The message will only include words from the dictionary.

Input

Take as input an encrypted message and a dictionary of words. The input can be taken in any form you like, however the preferred input is the message as a string and the dictionary as either a new-line deliminated string, an array or the file path of a file containing one word per line.

Output

Output the decrypted message in any format you like (although human-readable is preferred). The output must only contain words from the message.

Examples

These examples assume that the dictionary given is an English dictionary, such as the one included in Linux:

TLW EYQMA HJUIP BUN VYKZWR UDWJ TLW FCXS RUG FCOT IWWAWPR HYT TLWP PUTQMWR TLCT TLQO OWPTWPMW PWWRWR CRRQTQUPCF IUJRO TU HW WCOQFS BQNWR OU TLW BUN COAWR TLW RUG TU GWT CPUTLWJ OWPTWPMW, CPR ILWP TLW RUG JWBYOWR TLW BUN MJWCTWR UPW QPOTWCR
the quick brown fox jumped over the lazy dog last weekend but then noticed that this sentence needed additional words to be easily fixed so the fox asked the dog to get another sentence and when the dog refused the fox created one instead

VMXIBKGVW GVCG RH HLNVGRNVH XIVZGVW YB IVKOZXRMT LMV OVGGVI YB ZMLGSVI GSRH GVCG GVHGH BLF GL VMHFIV BLF XZM IVKOZXV HLNV LI ZOO LU GSV OVGGVIH RM GSV GVCG DRGS IVKOZXVNVMG OVGGVIH
encrypted text is sometimes created by replacing one letter by another this text tests you to ensure you can replace some or all of the letters in the text with replacement letters
\$\endgroup\$

marked as duplicate by Mego, Rɪᴋᴇʀ, Zach Gates, NinjaBearMonkey, SuperJedi224 Mar 18 '16 at 14:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
    \$\begingroup\$ Related \$\endgroup\$ – AdmBorkBork Mar 17 '16 at 20:26
  • \$\begingroup\$ Related. \$\endgroup\$ – Martin Ender Mar 17 '16 at 20:57
  • \$\begingroup\$ This is not a duplicate; that one has a hard-coded dictionary, this one uses an external dictionary. \$\endgroup\$ – wizzwizz4 Mar 24 '16 at 17:38