I have a string of 7 characters. I'm supposed to generate all the combinations. But some combinations are more likely than others, I would like the more likely ones to be generated first.

If I iterate from AAAAAAA to ZZZZZZZ, it's very unlikely that AAAAAAA is a valid combination. But BZYEKSO would be more likely being a password (more weight).

What algorithm would allow me to iterate through all combinations and come up with a random key that most likely resembles a valid pin?

If the string was 4 characters, I can pre-generate all the combinations and then scramble it for a better effect. But when the string is 7 characters long (better yet make it include numbers too). There's 36^7 combinations and there would not be enough memory to hold everything.

I'm thinking there's an encryption algorithm that can be used to randomly generate a string that is 7 characters long WITHOUT repeating. ie. I would iterate through the algorithm 36^7 times using 36^7 unique keys and it would give me a 36^7 random numbers that are of length 7 and doesn't repeat.

Is there anything for this that exist?



Regardless of whether this is a reasonable thing to do, it is possible to enumerate a large set with a random order without having to store them all in RAM. Basically, you need a permutation over your source set (the 7-character strings, of size 367) such that the permutation "looks randomish" and can be evaluated efficiently on each element. Such a permutation would be known as a block cipher.

Usual block ciphers use large binary blocks, i.e. work on the set of sequences of 64 or 128 bits, not on the set of sequences of 7 characters; however, other constructions are known which can bring decent security for such "small", non-binary blocks. This field of research is called format-preserving encryption. Rogaway's Thorp shuffle is one of the rather easy to implement proposals, and has decent efficiency.

Not the answer you're looking for? Browse other questions tagged or ask your own question.