Created
December 4, 2015 14:08
-
-
Save johnboker/9752bf86af847ca1ad7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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