HFE
Class Poly2MultiSquare

java.lang.Object
  |
  +--HFE.Poly2MultiSquare

final class Poly2MultiSquare
extends java.lang.Object

This class provides polynomials of degree two in n independent variables. The polynomials are over the finite field GF(2) which is provided in the class Field2.

Version:
0.1

Field Summary
private  int[] coeff
          Coefficients for the variables.
private  int varNum
          The number of variables in this polynomial.
 
Constructor Summary
Poly2MultiSquare()
          sets all the coefficients to zero assumes that the polynomial has no variables
Poly2MultiSquare(int varNum)
          Sets all the coefficients to zero by allocating new memory.
Poly2MultiSquare(int[] inArray)
          array2poly(int[])
Poly2MultiSquare(int varNum, int[] inArray)
          Creates a new object by using inArray for the coefficients.
Poly2MultiSquare(int varNum, java.util.Random rnd)
          Sets all the coefficients to a random value and also allocates new memory for these coefficients.
Poly2MultiSquare(Poly2MultiLinear father)
          Creates a copy from the given linear polynomial.
Poly2MultiSquare(Poly2MultiLinear a, Poly2MultiLinear b)
          Multiplies two lineare polynomials and stores the result in a new object.
Poly2MultiSquare(Poly2MultiSquare father)
          Creates a copy from the given polynomial.
 
Method Summary
 void add(int whom, int i)
          calculate this[i] += whom in terms of coefficient addition
 void add(Poly2MultiLinear whom)
          calculate this += whom as polynomial addition
 void add(Poly2MultiSquare whom)
          calculate this += whom as polynomial addition
 void add(Poly2MultiSquare a, Poly2MultiSquare b)
          calculates this = a + b as polynomial addition
 int apply(int[] values)
          Evaluate the polynomial using the given value vector.
static int apply(int[] coeffs, int[] values)
          Evaluate the polynomial using the given value vector and the given coefficient vector.
 void array2poly(int[] inArray)
          Sets the coefficients using the given coefficient.
 int[] coeffs()
          returns the coefficient array without copying it.
static void getValues(int[] rawValues, int[] res)
          Calculates the square values using the linear values.
 void initMem()
          Allocates new memory for the coefficients.
 boolean isEqual(Poly2MultiSquare whom)
          Compares this and whom coefficientwise.
 boolean isZero()
          Checks if the polynomial is the zero polynomial.
static void main(java.lang.String[] args)
          Mainly invoces the testIt() method.
 void mul(Poly2MultiLinear a, Poly2MultiLinear b)
          Calculates this = a*b in terms of polynomial multiplication.
 void mulAdd(int factor, Poly2MultiSquare whom)
          this += factor*whom.
 void mulAdd(Poly2MultiLinear a, Poly2MultiLinear b)
          Calculates this += a*b in terms of polynomial multiplication.
 void rnd(java.util.Random rnd)
          Sets all the coefficients to a random value without allocating new memory for these coefficients.
 void setCoeffs(int[] inArray)
          Sets all the coefficients by the given array.
 void setZero()
          Sets all the coefficients to zero without allocating new memory.
 void sub(Poly2MultiSquare whom)
          calculate this -= whom as polynomial subtraction
 void sub(Poly2MultiSquare a, Poly2MultiSquare b)
          calculates this = a - b as polynomial subtraction
static int tau_inverse(int t)
          Calulates the number of variables for a given number of terms t.
static int tau(int n)
          Calulates the number of terms for a given number of variables n by using the formula ((n+1)*(n+2))/2.
static void testIt()
          Tests the functionality for the whole class.
 void writeString()
          Writes the polynomial as a string to stdout
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

varNum

private int varNum
The number of variables in this polynomial.

coeff

private int[] coeff
Coefficients for the variables. The variables are x_1..x_n where n is varNum. Position 0 is for the constant term. Position n+1 is for x_1*x_1, n+2 is for x_1*x_2, ..., n+(n-1) is for x_1*x_n, n+n is for x_2*x_2, n+n+1 is for x_2*x_3, ...
Constructor Detail

Poly2MultiSquare

public Poly2MultiSquare()
sets all the coefficients to zero assumes that the polynomial has no variables

Poly2MultiSquare

public Poly2MultiSquare(int varNum)
Sets all the coefficients to zero by allocating new memory. Assumes that the polynomial has varNum variables.
Parameters:
varNum - number of variables for that polynomial

Poly2MultiSquare

public Poly2MultiSquare(int varNum,
                        java.util.Random rnd)
Sets all the coefficients to a random value and also allocates new memory for these coefficients. Assumes that the polynomial has varNum variables.
Parameters:
varNum - number of variables for that polynomial

Poly2MultiSquare

public Poly2MultiSquare(Poly2MultiSquare father)
Creates a copy from the given polynomial. Uses memory copy for the coefficients.

Poly2MultiSquare

public Poly2MultiSquare(Poly2MultiLinear father)
Creates a copy from the given linear polynomial. Uses memory copy for the coefficients.

Poly2MultiSquare

public Poly2MultiSquare(int[] inArray)
array2poly(int[])

Poly2MultiSquare

public Poly2MultiSquare(int varNum,
                        int[] inArray)
Creates a new object by using inArray for the coefficients. Does no checking for arguments, no memory copy.
Parameters:
varNum - number of variables for this object
inArray - coefficients for the multivaribale polynomial

Poly2MultiSquare

public Poly2MultiSquare(Poly2MultiLinear a,
                        Poly2MultiLinear b)
Multiplies two lineare polynomials and stores the result in a new object. The two lineare polynomials must have the same number of variables. The result is a polynomial of degree 2. This constructor also allocates new memory and is therefore quite slow. The faster version is mul(HFE.Poly2MultiLinear, HFE.Poly2MultiLinear)
Method Detail

tau

public static int tau(int n)
Calulates the number of terms for a given number of variables n by using the formula ((n+1)*(n+2))/2.

tau_inverse

public static int tau_inverse(int t)
Calulates the number of variables for a given number of terms t.

coeffs

public int[] coeffs()
returns the coefficient array without copying it.

isEqual

public boolean isEqual(Poly2MultiSquare whom)
Compares this and whom coefficientwise. If the two polynomials have different number of variables they can not be equal.
Returns:
true iff all the coefficients are the same both objects

isZero

public boolean isZero()
Checks if the polynomial is the zero polynomial.
Returns:
true iff all coefficients are zero

setZero

public void setZero()
Sets all the coefficients to zero without allocating new memory.

initMem

public void initMem()
Allocates new memory for the coefficients. The coefficients are initalized with zero.

setCoeffs

public void setCoeffs(int[] inArray)
Sets all the coefficients by the given array. Does neither memory copy nor argument checking.

array2poly

public void array2poly(int[] inArray)
Sets the coefficients using the given coefficient. Copies the array and checks if the array has the right length.
Throws:
IllegalArgumentException: - array has the wrong length, needs to be (varNum+1)

rnd

public void rnd(java.util.Random rnd)
Sets all the coefficients to a random value without allocating new memory for these coefficients.
Parameters:
rnd - random generator

add

public void add(Poly2MultiSquare a,
                Poly2MultiSquare b)
calculates this = a + b as polynomial addition

add

public void add(Poly2MultiSquare whom)
calculate this += whom as polynomial addition

add

public void add(int whom,
                int i)
calculate this[i] += whom in terms of coefficient addition

add

public void add(Poly2MultiLinear whom)
calculate this += whom as polynomial addition

sub

public void sub(Poly2MultiSquare a,
                Poly2MultiSquare b)
calculates this = a - b as polynomial subtraction

sub

public void sub(Poly2MultiSquare whom)
calculate this -= whom as polynomial subtraction

getValues

public static void getValues(int[] rawValues,
                             int[] res)
Calculates the square values using the linear values. I.e. uses a vector with the values for x_1, ... x_n (position 0 is not used) and calulates a vector with values for x_1, ... x_n, x_1^2, x_1*x_2, ... The position 0 in the output vector is not used.

apply

public int apply(int[] values)
Evaluate the polynomial using the given value vector. The entry value[0] is _not_ uses, value[1] is the first valid entry. This format is produces by getValues(int[], int[]).
Parameters:
values - array with tau(varNum) entries. tau(int)
Returns:
value of the current polynimial.

apply

public static int apply(int[] coeffs,
                        int[] values)
Evaluate the polynomial using the given value vector and the given coefficient vector. The entry value[0] is _not_ uses, value[1] is the first valid entry.
Parameters:
coeffs - coefficients of a multivariable, linear polynomial
values - values for the variables (and there squares) of the polynomial, value[1] is the value for the first variable, ...
Returns:
value of the current polynimial.

mul

public void mul(Poly2MultiLinear a,
                Poly2MultiLinear b)
Calculates this = a*b in terms of polynomial multiplication. a and b must have the same number of varialbes. The current value of this is discared.

mulAdd

public void mulAdd(int factor,
                   Poly2MultiSquare whom)
this += factor*whom. Multiplies whom with the scalar factor and adds the result to this.

mulAdd

public void mulAdd(Poly2MultiLinear a,
                   Poly2MultiLinear b)
Calculates this += a*b in terms of polynomial multiplication.

writeString

public void writeString()
Writes the polynomial as a string to stdout

testIt

public static void testIt()
Tests the functionality for the whole class. Reports errors to stdout.

main

public static void main(java.lang.String[] args)
Mainly invoces the testIt() method.