0

I have a question regarding the checking of possible permutations of something by using loops:

An encrypted sentence was formed by using a 26 slot char array. This array contained a randomized alphabet (every letter occurring only once), and every letter of the original unencrypted sentence was changed to whatever letter the array had at it's xth slot, x being the original characters position in the alphabet.

For example, if the encryption array had been {'q','w','e','r','t',...,'m'}, then the message "abez" would have become "qwtm" because:

a is the 1st letter of the alphabet and the 1st slot of the array contained a 'q'
b is the 2nd letter of the alphabet and the 2nd slot of the array contained a 'w'
e is the 5th letter of the alphabet and the 5th slot of the array contained a 't'
...

I'd like to bruteforce the encrypted sentence by checking every permutation for the keyword "morning".

How do I do this correctly? I already wrote a method that checks whether a char[] is contained in another char[], but how can I loop through the char[] permutations?

Jake
  • 143
  • 1
  • 8
  • Here's how to create all permutations of the alphabet: http://stackoverflow.com/questions/361/generate-list-of-all-possible-permutations-of-a-string (oldest question I've ever linked to) – Thilo Nov 25 '12 at 02:14
  • There are 403291461126605635584000000 permutations of the alphabet. If you want to brute-force that, you need a heck of a lot of hardware. – Daniel Fischer Nov 25 '12 at 02:30

1 Answers1

0

What you need to do is loop through your string's characters, and for each of it change it to all the other letters. You can have a function which takes the following parameters:

  1. String to be converted
  2. Letters of the alphabet already taken

and returns all the combinations.

You can then call it recursively for each letter in the word (morning) and it returns a list of all possible words. When calling itself recursively, and the 'child' function returns, the parent function loops through all the answers, and for each of them prefixes its own letter. It has to do this (call recursively and prefix letter) for all letters exlcuding the letters already taken.

Expect this to take a lot of time.

jbx
  • 21,365
  • 18
  • 90
  • 144