public void testEncodeDecodeModQ()
 {
     int[]  coeffs  = PolynomialGenerator.GenerateRandom(1000, 2048).coeffs;
     byte[] data    = ArrayEncoder.EncodeModQ(coeffs, 2048);
     int[]  coeffs2 = ArrayEncoder.DecodeModQ(data, 1000, 2048);
     Assert.True(coeffs.SequenceEqual(coeffs2));
 }
示例#2
0
        /// <summary>
        /// Encodes the polynomial to a byte array writing <c>BITS_PER_INDEX</c> bits for each coefficient
        /// </summary>
        ///
        /// <returns>The encoded polynomial</returns>
        public byte[] ToBinary()
        {
            int maxIndex = 1 << BITS_PER_INDEX;

            byte[] bin1 = ArrayEncoder.EncodeModQ(m_ones, maxIndex);//13l - (9,2048)
            byte[] bin2 = ArrayEncoder.EncodeModQ(m_negOnes, maxIndex);
            byte[] bin  = ArrayUtils.Concat(ArrayEncoder.ToByteArray(m_ones.Length), ArrayEncoder.ToByteArray(m_negOnes.Length), bin1, bin2);

            return(bin);
        }
        private void EncodeDecodeModQ()
        {
            int[]  coeffs  = PolynomialGeneratorForTesting.generateRandomPositive(1000, 2048).Coeffs;
            byte[] data    = ArrayEncoder.EncodeModQ(coeffs, 2048);
            int[]  coeffs2 = ArrayEncoder.DecodeModQ(data, 1000, 2048);

            if (!Compare.AreEqual(coeffs, coeffs2))
            {
                throw new Exception("ArrayEncoder EncodeDecodeModQ test failed!");
            }
        }
示例#4
0
        /**
         * Encodes the polynomial to a byte array writing <code>BITS_PER_INDEX</code> bits for each coefficient.
         *
         * @return the encoded polynomial
         */
        public byte[] ToBinary()
        {
            int maxIndex = 1 << BITS_PER_INDEX;

            byte[] bin1 = ArrayEncoder.EncodeModQ(Ones, maxIndex);
            byte[] bin2 = ArrayEncoder.EncodeModQ(NegOnes, maxIndex);

            byte[] bin = new byte[bin1.Length + bin2.Length];
            Array.Copy(bin1, bin, bin1.Length);
            Array.Copy(bin2, 0, bin, bin1.Length, bin2.Length);
            return(bin);
        }
示例#5
0
 /**
  * Encodes a polynomial whose coefficients are between 0 and q, to binary. q must be a power of 2.
  *
  * @param q
  * @return the encoded polynomial
  */
 public byte[] ToBinary(int q)
 {
     return(ArrayEncoder.EncodeModQ(coeffs, q));
 }