10 binary to 62, implements all cipher combinations (brute force) for the specified number of digits

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.