static void Main(string[] args) { var originalList = ListGenerator.MakeValueEqualsIndexList(256); var knotterPart1 = new ListKnotter <int>(originalList); var lengthsPart1 = LENGTHS_STRING.Split(',').Select(s => int.Parse(s)).ToList(); var outputPart1 = knotterPart1.ApplyTwists(lengthsPart1, 1); var product = outputPart1[0] * outputPart1[1]; Console.WriteLine("Product of first two values of twisted list for part 1: {0}", product); var outputPart2 = KnotHasher.Hash(LENGTHS_STRING); Console.WriteLine("Hashed value for part 2: {0}", outputPart2); Console.ReadLine(); }
public static string Hash(string input) { var lengths = AsciiConverter.ConvertString(input); lengths.AddRange(APPENDED_LENGTH_SEQUENCE); var listToKnot = ListGenerator.MakeValueEqualsIndexList(256); var knotter = new ListKnotter <int>(listToKnot); var sparseHash = knotter.ApplyTwists(lengths, 64); var denseHash = new List <int>(); for (int i = 0; i < 16; i++) { var range = sparseHash.GetRange(i * 16, 16); var denseValue = range.Aggregate((x, y) => x ^ y); denseHash.Add(denseValue); } var hash = denseHash.Aggregate("", (agg, next) => agg + next.ToString("X2")); return(hash.ToLower()); }