The question is: how to make the software generate a password of 4 long characters and calculate the hash of md5 from each line, and then when I register the first 2 characters of the password, let's say "c5" there, then did the software print these passwords in which the hash starts with "c5"? I repeat this question because no answer so far

Closed due to the fact that the essence of the question is not clear to the participants of rdorn , cheops , user194374, Kromster , AseN Jun 13 '16 at 22:30 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin

1 answer 1

Based on comments:

We have alphabet: az AZ 0-9 (62 characters)

You need to get all the passwords with a length of 5 characters.

Let us estimate the scale of the tragedy: 62 ^ 5 = 916132832 passwords, which is less than 2 ^ 63, which means you can use a simple translation from the 10-hr to the 62-th number system.

Let us set the alphabet as follows:

string alph = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; long startPassNum = 0; long endPassNum = 916132832; string resultPass; for (long current = startPassNum; current < endPassNum; current++) { //теперь переведем в число в нужное представление StringBuilder pass = new StringBuilder(5); while((current % alph.Length) > 0) { pass.Insert(0, alph[current % alph.Length]); current = current / alph.Length; } //первую половину всех паролей придется дополнять до нужного числа знаков while(pass.Length<5) { pass.Insert(0, alph[0]); } resultPass = pass.ToString(); pass.Clear(); // тут что-то делаем с паролем из resultPass } 

This approach allows you to get a password just by its number, which makes, at the same time, simplifies random generation, reducing it to generating a random password number.

The method is well parallelized into streams, if necessary, by simple partitioning of password numbers into intervals.

  • That is, in your opinion, is this the shortest possible one? - komra23
  • In this case, yes, for large lengths of passwords or the alphabet 2 ^ 63 may not be enough and you have to be wise, but here everything is simple - rdorn
  • he, moreover, is also relatively fast. In principle, even without streams in a few hours should handle a good iron. As a last resort, you can for replace Parallel.For() , an example here msdn.microsoft.com/ru-ru/library/… - rdorn
  • only then the resultPass announcement needs to be removed inside the loop - rdorn
  • I'm talking about the code below which - komra23