Because we're going to be poor here. The password includes 0-9,a-z,a-z a total of 62 characters, so we use 62 binary to traverse.
First, we implement a 10 binary to 62 binary method.
private static char[] CharSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". ToCharArray (); private static string[] CharSet = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",// "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",// "N", "O", "P", "Q", "R", "s", "T", "U", "V", "w", "X", "Y", "z",//"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",//"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; <summary>////Convert the specified number to a specified length of 62 binary///</summary>//<param name= "value" > the number to be converted &l t;/param>//<param name= "Length" > Required length </param>//<returns>62 binary presentation format </returns> public static string ConvertTo62 (Long value, int length) { String sixtynum = String. Empty; if (value < sixtynum) {= Charset[value]. ToString (). PadLeft (length, ' 0 '); } else {long result = value; char[] ch = new Char[length]; while (Result > 0) {long val = result% 62; Ch[--length] = Charset[val]; Sixtynum = Charset[val] + sixtynum; result = RESULT/62; } sixtynum = sixtynum.padleft (length, ' 0 '); for (int i = 0; i < length; i++)//{//ch[i] = ' 0 '; }//sixtynum = new string (CH); } return sixtynum; }
The test found that defining charset as a char is a bit faster than string, but the calculations in the horse are also made in char (the code I commented out) is faster.
Console.WriteLine (CONVERTTO62 (520, 5));//output: 0008o
Since 520 the conversion becomes 62 the binary is 8o, less than 5 bits in front plus 0 padded.
Then, we can write a method to traverse the password of the specified length.
<summary>//// traversal of all combinations between the specified digits///</summary>// <param name= "minLength" > Shortest number of digits </ Param> //<param name= "maxLength" > Longest digits </param> public static void Testpassword (int minLength , int maxLength) {for (int i = minLength; I <= maxLength; i++) { Long maxnum = (long) Math.pow (); C10/>for (Long j = 0; J < Maxnum; J + +) { Console.WriteLine (ConvertTo62 (J, I));} }}
Call:
Testpassword (2, 3);
The program will output all combinations of 2-bit and 3-bit passwords. (From: 00-zzz)
According to this idea, we can also write more forms of the exhaustive algorithm. For example, we traverse the password also contains the decimal point ".", then we just need to change the algorithm to 63 binary.
10 binary to 62, implements all cipher combinations (brute force) for the specified number of digits