public string BreakXor() { byte [] bestBytes = null; int bestScore = int.MinValue; var hex = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"; var bytes = Util.HexToBytes(hex); for (var j = 0; j < 256; j++) { var keyByte = (byte)j; var keyBytes = new byte [256]; for (var i = 0; i < keyBytes.Length; i++) { keyBytes[i] = keyByte; } var result = new Challenge2().Xor(bytes, keyBytes); var score = Score(result); if (j == 0) { bestBytes = result; bestScore = score; } else if (score > bestScore) { bestBytes = result; bestScore = score; } } var resultText = new string(bestBytes.Select(x => (char)x).ToArray()); return(resultText); }
public void WebTest() { var hex0 = "1c0111001f010100061a024b53535009181c"; var hex1 = "686974207468652062756c6c277320657965"; var expectedHex = "746865206b696420646f6e277420706c6179"; var challenge = new Challenge2(); var result = Util.ToHex(challenge.Xor(Util.HexToBytes(hex0), Util.HexToBytes(hex1))); result.ShouldBe(expectedHex); }