예제 #1
0
        private static byte[] GetKey(byte[] bytes, int keySize)
        {
            var blocks = new byte[keySize][];
            var mod    = bytes.Length % keySize;

            for (var i = 0; i < keySize; i++)
            {
                var length = mod == 0 || i < mod ? keySize : keySize - 1;
                blocks[i] = new byte[length];
                for (var j = 0; j < length; j++)
                {
                    blocks[i][j] = bytes[j * keySize + i];
                }
            }

            var key = new byte[keySize];

            for (var i = 0; i < keySize; i++)
            {
                var score = Challenge3.DecodeSingleByteXORCipher(blocks[i]);
                key[i] = score.Cipher[0];
            }

            return(key);
        }
예제 #2
0
 public static TextScore FindDecodedText(string[] inputs)
 {
     return(inputs.Select(i => Challenge3.DecodeSingleByteXORCipher(i)).OrderByDescending(s => s.Score).First());
 }