Skip to content

Instantly share code, notes, and snippets.

@johnboker
Created December 4, 2015 14:08
Show Gist options
  • Save johnboker/9752bf86af847ca1ad7a to your computer and use it in GitHub Desktop.
Save johnboker/9752bf86af847ca1ad7a to your computer and use it in GitHub Desktop.
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