You know those riddles where every letter is swapped for another letter?
E.g. you get a text like
JME JG EPP IFAPE EPJE CJPPPC BP,
UIJCG JC EPP EFE GPJB EJIP EJ EJIP,
F EPJIG MPJEPPPP AJUC BJL UP
GJP BL MICJIJMPPJUIP CJMI.
and are supposed to find out that it stands for
OUT OF THE NIGHT THAT COVERS ME,
BLACK AS THE PIT FROM POLE TO POLE,
I THANK WHATEVER GODS MAY BE
FOR MY UNCONQUERABLE SOUL.
This example was created by the following replacement matrix:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ODSXHKARFYGNBIQTJVCEWZMULP
Try to unscramble any given text by doing a letter frequency analysis. Assume that the most common letters in the given input are (left to right):
EARIOTNSLCUDPMHGBFYWKVXZJQ
- Replace the most common letter in the input by E, the next most common by A, and so on
- Producing a correctly unscrambled text is actually outside the scope of this challenge. That is, we assume that you get a correct result if only the input is large enough. (Testcase 1)
- If there is insufficient data, your return value must be consistent with the data provided. (Testcase 2)
- You may expect uppercase text only. It can contain digits, punctuations etc., which are not scrambled and to be output as is.
This is a code golf, shortest answer in bytes wins. Standard loopholes apply.
Testcase 1 - The shortest completely solvable one
CCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPPPPPPPPIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPPPPFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGEEEEEEEEEEEEEEEEEIIIIIIIIIIIIIIIITTTTTTTTTTTTTTTMMMMMMMMMMMMMMJJJJJJJJJJJJJAAAAAAAAAAAAAAAAAAAAAAAWWWWWWWWWWDDDDDDDDDBBBBBBBBBBBBBBBFFFFFFTTTTTJJJJWWWIIP
must output
EEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRRRIIIIIIIIIIIIIIIIIIIIIIIOOOOOOOOOOOOOOOOOOOOOOTTTTTTTTTTTTTTTTTTTTTNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLCCCCCCCCCCCCCCCCCUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDPPPPPPPPPPPPPPMMMMMMMMMMMMMHHHHHHHHHHHHGGGGGGGGGGGBBBBBBBBBBFFFFFFFFFYYYYYYYYWWWWWWWKKKKKKVVVVVXXXXZZZJJQ
Testcase 2
HALLO WORLD
must output ??EEA<space>?A?E?
:
- The 3 Ls turn into E
- The 2 Os turn into A
- The remaining letters are each replaced by an undefined permutation of the letters "RIOTN", without any of these repeating.