Program.cs 847 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. namespace D04._1
  7. {
  8. class Program
  9. {
  10. static byte[] ToB(string str) => Encoding.ASCII.GetBytes(str);
  11. static string ToS(byte[] b) => BitConverter.ToString(b).Replace("-", "");
  12. static void Main(string[] args)
  13. {
  14. if (args.Length < 1) throw new ArgumentException();
  15. string hash = args[0];
  16. int nbr = 0;
  17. using (var md5 = MD5.Create())
  18. {
  19. do
  20. {
  21. var h = md5.ComputeHash(ToB($"{hash}{nbr}"));
  22. if (ToS(h).StartsWith("00000")) break;
  23. nbr++;
  24. } while (true);
  25. }
  26. Console.WriteLine($"Answer is : {nbr}");
  27. }
  28. }
  29. }