public class ArrayEncoder
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int[] |
BIT1_TABLE
Coefficient to bit string conversion table from P1363.1.
|
private static int[] |
BIT2_TABLE |
private static int[] |
BIT3_TABLE |
private static int[] |
COEFF1_TABLE
Bit string to coefficient conversion table from P1363.1.
|
private static int[] |
COEFF2_TABLE |
Constructor and Description |
---|
ArrayEncoder() |
Modifier and Type | Method and Description |
---|---|
static int[] |
decodeMod3Sves(byte[] data,
int N)
Decodes a
byte array encoded with encodeMod3Sves(int[]) back to an int array
with N coefficients between -1 and 1 .Ignores any excess bytes. See P1363.1 section 9.2.2. |
static int[] |
decodeMod3Tight(byte[] b,
int N)
Converts a byte array produced by
encodeMod3Tight(int[]) back to an int array. |
static int[] |
decodeMod3Tight(java.io.InputStream is,
int N)
Converts data produced by
encodeMod3Tight(int[]) back to an int array. |
static int[] |
decodeModQ(byte[] data,
int N,
int q)
Decodes a
byte array encoded with encodeModQ(int[], int) back to an int array.N is the number of coefficients. |
static int[] |
decodeModQ(java.io.InputStream is,
int N,
int q)
Decodes data encoded with
encodeModQ(int[], int) back to an int array.N is the number of coefficients. |
static byte[] |
encodeMod3Sves(int[] arr)
Encodes an
int array whose elements are between -1 and 1 , to a byte array. |
static byte[] |
encodeMod3Tight(int[] intArray)
Encodes an
int array whose elements are between -1 and 1 , to a byte array. |
static byte[] |
encodeModQ(int[] a,
int q)
Encodes an int array whose elements are between 0 and
q ,
to a byte array leaving no gaps between bits.q must be a power of 2. |
private static int |
getBit(byte[] arr,
int bitIndex) |
private static final int[] COEFF1_TABLE
http://stackoverflow.com/questions/1562548/how-to-make-a-message-into-a-polynomial
Convert each three-bit quantity to two ternary coefficients as follows, and concatenate the resulting
ternary quantities to obtain [the output].
{0, 0, 0} -> {0, 0}
{0, 0, 1} -> {0, 1}
{0, 1, 0} -> {0, -1}
{0, 1, 1} -> {1, 0}
{1, 0, 0} -> {1, 1}
{1, 0, 1} -> {1, -1}
{1, 1, 0} -> {-1, 0}
{1, 1, 1} -> {-1, 1}
private static final int[] COEFF2_TABLE
private static final int[] BIT1_TABLE
http://stackoverflow.com/questions/1562548/how-to-make-a-message-into-a-polynomial
Convert each set of two ternary coefficients to three bits as follows, and concatenate the resulting bit
quantities to obtain [the output]:
{-1, -1} -> set "fail" to 1 and set bit string to {1, 1, 1}
{-1, 0} -> {1, 1, 0}
{-1, 1} -> {1, 1, 1}
{0, -1} -> {0, 1, 0}
{0, 0} -> {0, 0, 0}
{0, 1} -> {0, 0, 1}
{1, -1} -> {1, 0, 1}
{1, 0} -> {0, 1, 1}
{1, 1} -> {1, 0, 0}
private static final int[] BIT2_TABLE
private static final int[] BIT3_TABLE
public static byte[] encodeModQ(int[] a, int q)
q
,
to a byte array leaving no gaps between bits.q
must be a power of 2.a
- the input arrayq
- the moduluspublic static int[] decodeModQ(byte[] data, int N, int q)
byte
array encoded with encodeModQ(int[], int)
back to an int
array.N
is the number of coefficients. q
must be a power of 2
.data
- an encoded ternary polynomialN
- number of coefficientsq
- N
coefficients between 0
and q-1
public static int[] decodeModQ(java.io.InputStream is, int N, int q) throws java.io.IOException
encodeModQ(int[], int)
back to an int
array.N
is the number of coefficients. q
must be a power of 2
.is
- an encoded ternary polynomialN
- number of coefficientsq
- java.io.IOException
public static int[] decodeMod3Sves(byte[] data, int N)
byte
array encoded with encodeMod3Sves(int[])
back to an int
array
with N
coefficients between -1
and 1
.data
- an encoded ternary polynomialN
- number of coefficientspublic static byte[] encodeMod3Sves(int[] arr)
int
array whose elements are between -1
and 1
, to a byte array.
coeffs[2*i]
and coeffs[2*i+1]
must not both equal -1 for any integer i,
so this method is only safe to use with arrays produced by decodeMod3Sves(byte[], int)
.
See P1363.1 section 9.2.3.
arr
- public static byte[] encodeMod3Tight(int[] intArray)
int
array whose elements are between -1
and 1
, to a byte array.public static int[] decodeMod3Tight(byte[] b, int N)
encodeMod3Tight(int[])
back to an int
array.b
- a byte arrayN
- number of coefficientspublic static int[] decodeMod3Tight(java.io.InputStream is, int N) throws java.io.IOException
encodeMod3Tight(int[])
back to an int
array.is
- an input stream containing the data to decodeN
- number of coefficientsjava.io.IOException
private static int getBit(byte[] arr, int bitIndex)