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));
        }
        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!");
                    }
                }
            }
        }
Example #3
0
 /**
  * Decodes a byte array to a polynomial with <code>N</code> ternary coefficients<br>
  * Ignores any excess bytes.
  *
  * @param data an encoded ternary polynomial
  * @param N    number of coefficients
  * @return the decoded polynomial
  */
 public static IntegerPolynomial FromBinary3Sves(byte[] data, int N)
 {
     return(new IntegerPolynomial(ArrayEncoder.DecodeMod3Sves(data, N)));
 }