Let’s say the domain is as following
String domain[] = { a, b, .., z, A, B, .. Z, 0, 1, 2, .. 9 };
Let’s say the password size is 8
ArrayList allCombinations = getAllPossibleStrings2(domain,8);
This is going to generate SIZE(domain) * LENGTH
number of combinations, which is in this example (26+26+10)^8 = 62^8 = 218,340,105,584,896
combinations
Then you can enumerate all possible string up\at to a specific size like this
// get all possible combinations up to a given size
static ArrayList getAllPossibleStrings1(ArrayList domain, int maxSize)
{
ArrayList list = new ArrayList();
int i = 1;
list.AddRange(domain);
while(++i <= maxSize)
for(String a in list)
for(String b in domain)
list.Add(String.Concat(a,b));
return list;
}
// get all possible combinations at a given size
static ArrayList getAllPossibleStrings2(ArrayList domain, int size)
{
ArrayList list = new ArrayList();
ArrayList temp = new ArrayList();
int i = 1;
list.AddRange(domain);
while(++i <= maxSize)
{
for(String a in list)
for(String b in domain)
temp.Add(String.Concat(a,b));
list.Clear();
list.AddRange(temp);
temp.Clear();
}
return list;
}
solved Does there exist an algorithm for iterating through all strings that conform to a particular regex?