Ejemplo n.º 1
0
        public void testEncodeDecodeMod3Sves()
        {
            Random rng = new Random();

            byte[] data = new byte[180];
            rng.NextBytes(data);
            int[]  coeffs = ArrayEncoder.DecodeMod3Sves(data, 960);
            byte[] data2  = ArrayEncoder.EncodeMod3Sves(coeffs);
            Assert.True(data.SequenceEqual(data2));
        }
Ejemplo n.º 2
0
        private void EncodeDecodeMod3Sves()
        {
            Random rng = new Random();

            bool[] skip = new bool[] { true, false };

            foreach (bool skipFirst in skip)
            {
                for (int i = 0; i < 10; i++)
                {
                    int    N    = (rng.Next(1000) + 100) * 16;
                    byte[] data = new byte[N * 3 / 16];
                    rng.NextBytes(data);
                    data[data.Length - 1] = 0;
                    int[]  coeffs = ArrayEncoder.DecodeMod3Sves(data, N, skipFirst);
                    byte[] data2  = ArrayEncoder.EncodeMod3Sves(coeffs, skipFirst);
                    if (!Compare.AreEqual(data, data2))
                    {
                        throw new Exception("ArrayEncoder EncodeDecodeMod3Sves test failed!");
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /**
  * Encodes a polynomial with ternary coefficients to binary.
  * <code>coeffs[2*i]</code> and <code>coeffs[2*i+1]</code> must not both equal -1 for any integer <code>i</code>,
  * so this method is only safe to use with polynomials produced by <code>fromBinary3Sves()</code>.
  *
  * @return the encoded polynomial
  */
 public byte[] ToBinary3Sves()
 {
     return(ArrayEncoder.EncodeMod3Sves(coeffs));
 }