public void Challenge08_DetectEcb() { var lines = File.ReadAllLines("8.txt"); var candidates = new Dictionary <int, double>(lines.Length); for (var i = 0; i < lines.Length; i++) { var line = lines[i]; var cipher = Hex.ToBytes(line); var same = new HashSet <int>(cipher.Length / 16); for (int segment1 = 0; segment1 < cipher.Length / 16; ++segment1) { if (same.Contains(segment1)) { continue; } for (int segment2 = segment1 + 1; segment2 < cipher.Length / 16; ++segment2) { if (same.Contains(segment2)) { continue; } if (0 == Hamming.GetDistance(cipher.AsSpan(segment1 * 16, 16), cipher.AsSpan((segment2) * 16, 16))) { same.Add(segment1); same.Add(segment2); } } } candidates[i + 1] = same.Count; } var lnNr = candidates.OrderByDescending(x => x.Value).First().Key; Assert.Equal(133, lnNr); }
public void GetHammingDistance_EmptyStrands_DistanceIsZero() { Assert.AreEqual(0, Hamming.GetDistance(string.Empty, string.Empty)); }
public void GetHammingDistance_SecondStrandLonger_ThrowsArgumentException() { Assert.Throws <ArgumentException>(() => Hamming.GetDistance("ATA", "AGTG")); }
public void GetHammingDistance_FirstStrandLonger_ThrowsArgumentException() { Assert.Throws <ArgumentException>(() => Hamming.GetDistance("AATG", "AAA")); }
public void GetHammingDistance_OneNonUniqueCharacterInStrand_DistanceIsOne() { Assert.AreEqual(1, Hamming.GetDistance("AAA", "AAG")); }
public void GetHammingDistance_LongStrandsWithTwoDifference_DistanceIsTwo() { Assert.AreEqual(2, Hamming.GetDistance("ACCAGGG", "ACTATGG")); }
public void GetHammingDistance_SmallStrandsWithTwoDifference_DistanceIsTwo() { Assert.AreEqual(2, Hamming.GetDistance("AG", "CT")); }
public void GetHammingDistance_SmallStrandsWithOneDifference_DistanceIsOne() { Assert.AreEqual(1, Hamming.GetDistance("AT", "CT")); }
public void GetHammingDistance_OneDifference_DistanceOne() { Assert.AreEqual(1, Hamming.GetDistance("A", "G")); }
public void GetHammingDistance_IdenticalStrands_DistanceIsZero(string strand) { Assert.AreEqual(0, Hamming.GetDistance(strand, strand)); }