Program.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Security.Cryptography;
  3. using System.Text;
  4. namespace D05._2
  5. {
  6. class Program
  7. {
  8. static byte[] ToB(string str) => Encoding.ASCII.GetBytes(str);
  9. static string ToS(byte[] b) => BitConverter.ToString(b).Replace("-", "");
  10. static void Main(string[] args)
  11. {
  12. if (args.Length < 1) throw new ArgumentException();
  13. string input = args[0];
  14. var password = new char[8];
  15. int found = 0;
  16. using (var md5 = MD5.Create())
  17. {
  18. int i = 0;
  19. while (found < 8)
  20. {
  21. var h = md5.ComputeHash(ToB($"{input}{i}"));
  22. var sh = ToS(h);
  23. if (sh.StartsWith("00000") && sh[5] < '8')
  24. {
  25. int p = sh[5] - '0';
  26. if (password[p] == '\0')
  27. {
  28. found++;
  29. password[p] = sh[6];
  30. }
  31. }
  32. i++;
  33. }
  34. }
  35. Console.WriteLine($"Password is : {string.Join("", password)}");
  36. }
  37. }
  38. }