Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts the Private key to an encoded byte array
        /// </summary>
        ///
        /// <returns>The encoded NTRUPrivateKey</returns>
        public byte[] ToBytes()
        {
            int flags = (m_sparse ? 1 : 0) + (m_fastFp ? 2 : 0) + (PolyType == TernaryPolynomialType.PRODUCT ? 4 : 0);

            byte[] flagsByte = new byte[] { (byte)flags };
            byte[] tBin;

            if (T.GetType().Equals(typeof(ProductFormPolynomial)))
            {
                tBin = ((ProductFormPolynomial)T).ToBinary();
            }
            else
            {
                tBin = T.ToIntegerPolynomial().ToBinary3Tight();
            }

            return(ArrayUtils.Concat(ArrayEncoder.ToByteArray(N), ArrayEncoder.ToByteArray(Q), flagsByte, tBin));
        }
Esempio n. 3
0
 /// <summary>
 /// Converts the Public key to an encoded byte array
 /// </summary>
 ///
 /// <returns>The encoded NTRUPublicKey</returns>
 public byte[] ToBytes()
 {
     return(ArrayUtils.Concat(ArrayEncoder.ToByteArray(N), ArrayEncoder.ToByteArray(Q), H.ToBinary(Q)));
 }