Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
 public void Challenge05_RepeatingXOR()
 {
     Assert.Equal("0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f",
                  Hex.ToString(Xor.ApplyRepeating(Encoding.UTF8.GetBytes("Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal"), Encoding.UTF8.GetBytes("ICE"))));
 }