Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Security.Cryptography;
using System.Text;
namespace AdventOfCodeDay4
{
class Program
{
static void Main()
{
var input = "ckczppom";
using (var md5Hash = MD5.Create())
{
var found5 = false;
for(var i = 0; ; i++)
{
var hash = GetMd5Hash(md5Hash, $"{input}{i}");
if (!found5 && hash.StartsWith("00000"))
{
Console.WriteLine(i);
found5 = true;
}
if (hash.StartsWith("000000"))
{
Console.WriteLine(i);
break;
}
}
}
Console.ReadLine();
}
static string GetMd5Hash(MD5 md5Hash, string input)
{
var data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
var sBuilder = new StringBuilder();
foreach (byte t in data)
{
sBuilder.Append(t.ToString("x2"));
}
return sBuilder.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.