Ejemplo n.º 1
0
        /// <summary>
        /// This is helper method to generate lookup table for decoding strings, encoded with given look up table using various encoding methods (e.g. <see cref="EncodeBinary(Byte[], Int32, Int32, Char[])"/>, <see cref="EncodeBase64(Byte[], Boolean)"/>) in this class.
        /// </summary>
        /// <param name="encodeLookupTable">The table used to encode binary data.</param>
        /// <returns>The array with 256 elements, with character used as index giving the numerical value of it.</returns>
        /// <exception cref="IndexOutOfRangeException">If any character in <paramref name="encodeLookupTable"/> has its integer value 256 or greater.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="encodeLookupTable"/> is <c>null</c>.</exception>
        public static Int32[] CreateDecodeLookupTable(Char[] encodeLookupTable)
        {
            ArgumentValidator.ValidateNotNull("Encode lookup table", encodeLookupTable);
            var retVal = new Int32[Byte.MaxValue];

            retVal.Fill(-1);
            for (var i = 0; i < encodeLookupTable.Length; ++i)
            {
                retVal[(Int32)encodeLookupTable[i]] = i;
            }

            return(retVal);
        }