I’m playing a game where an Enigma M3 cipher is being used. It isn’t meant to be played this way, but I’m finding it fun. For the current clue, the plug board for the cipher isn’t known.
A plug board string looks like this: “bq cr di ej kw mt os px uz gh”
Here are the rules for this particular plug board:
- Letters can only be used once: “ab cc de” is an invalid plug
- It can be 0-20 characters
- It must be an even number of letters: “ab” is valid, but “ab c” is not
I’m trying to generate all possible combinations in javascript but struggling. Or rather, I’m struggling to do this in the most efficient way.
Since I know the answer-plug-board is likely in English, it’s probably pretty short; it’s difficult to come up with long phrases under the above constraint. So it’s better to try shorter answers first.
What’s the most efficient algorithm to do this in javascript?