I need to generate all upper and lower case permutations of the word 'password',however sometimes I swop out the chars a for @, s for 5 and o for 0,so I need to come up with all combinations so that my dictionary can eventually crack the password.This is a homework question btw.
I have already gotten a permutation to work on upper and lowercase but im unsure as to how to proceed to the steps where I substitute letters for symbols/numbers.
public List<string> permute(String input)
{
var list = new List<string>();
int n = input.Length;
// Number of permutations is 2^n
int max = 1 << n;
// Converting string
// to lower case
input = input.ToLower();
// Using all subsequences
// and permuting them
for (int i = 0; i < max; i++)
{
char[] combination = input.ToCharArray();
// If j-th bit is set, we
// convert it to upper case
for (int j = 0; j < n; j++)
{
if (((i >> j) & 1) == 1)
combination[j] = (char)(combination[j] - 32);
}
string tmp = new string(combination);
bool add = false;
//if combination contains 32(space) ,16(0),21(5) and dont add
foreach (char c in combination)
{
if (((c) == 32) || (c) == 16 || (c) == 21) //add 0 and 5
{
//dont add
add = false;
//break on first instance
break;
}
else
{
add = true;
}
}
// Printing current combination
Console.Write(combination);
Console.Write(" ");
if (add) list.Add(tmp);
}
return list;
}
static void Main(string[] args)
{
var pass1 = new List<string>();
var pass2 = new List<string>();
var pass3 = new List<string>();
var pass4 = new List<string>();
var pass5 = new List<string>();
Permute p = new Permute();
pass1 = p.permute("password");//this works well
//Replae a with @
pass2 = p.permute("p@ssword"); //remove all values with no a
//REplace o with 0
pass3 = p.permute("passw0rd"); //remove all values with no o
//Replace 5 with s
pass4 = p.permute("pa55word");
}
So to me, it seems im on the right track, but I can see that im actually going to be missing some of these sets and then im not going to crack the password.I need to use the results of the previous set somehow.
In the above im never going to get a value of say P@55w0rd, and that could be the correct answer.