public void Challenge03_SingleByteBreakXOR() { var bytes = Hex.ToBytes("1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"); var bestMatch = Xor.XorBestMatch(bytes).First(); var plainText = Encoding.UTF8.GetString(Xor.ApplyRepeating(bytes, new [] { bestMatch.key })); Assert.Equal("Cooking MC's like a pound of bacon", plainText); }
public void Challenge04_FindXORInFile() { var lines = File.ReadAllLines("4.txt"); var candidates = new List <(string line, byte key, double score)>(lines.Length); foreach (var line in lines) { var c = Xor.XorBestMatch(Hex.ToBytes(line)).First(); candidates.Add((line, c.key, c.score)); } var candidate = candidates.OrderByDescending(x => x.score).First(); var plainText = Encoding.UTF8.GetString(Xor.ApplyRepeating(Hex.ToBytes(candidate.line), new [] { candidate.key })); Assert.Equal("Now that the party is jumping\n", plainText); }