예제 #1
0
        /// <summary>
        /// Converts data produced by EncodeMod3Tight(int[]) back to an <c>int</c> array
        /// </summary>
        ///
        /// <param name="InputStream">The input stream containing the data to decode</param>
        /// <param name="N">The number of coefficients</param>
        ///
        /// <returns>The decoded array</returns>
        public static int[] DecodeMod3Tight(MemoryStream InputStream, int N)
        {
            int size = (int)Math.Ceiling(N * Math.Log(3) / Math.Log(2) / 8);

            byte[] arr = ArrayEncoder.ReadFullLength(InputStream, size);

            return(DecodeMod3Tight(arr, N));
        }
예제 #2
0
        /// <summary>
        /// Decodes data encoded with encodeModQ(int[], int) back to an <c>int</c> array.
        /// <para><c>N</c> is the number of coefficients. <c>q</c> must be a power of <c>2</c>.
        /// Ignores any excess bytes.</para>
        /// </summary>
        ///
        /// <param name="InputStream">An encoded ternary polynomial</param>
        /// <param name="N">The number of coefficients</param>
        /// <param name="Q">The modulus</param>
        ///
        /// <returns>The decoded polynomial</returns>
        public static int[] DecodeModQ(Stream InputStream, int N, int Q)
        {
            int qBits = 31 - IntUtils.NumberOfLeadingZeros(Q);
            int size  = (N * qBits + 7) / 8;

            byte[] arr = ArrayEncoder.ReadFullLength(InputStream, size);

            return(DecodeModQ(arr, N, Q));
        }