java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.Vector
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2Vector

public class GF2Vector extends Vector
This class implements the abstract class Vector for the case of vectors over the finite field GF(2).
For the vector representation the array of type int[] is used, thus one element of the array holds 32 elements of the vector.
See Also:
  • Field Summary Link icon

    Fields inherited from class org.bouncycastle.pqc.legacy.math.linearalgebra.Vector Link icon

    length
  • Constructor Summary Link icon

    Constructors
    Modifier
    Constructor
    Description
     
    GF2Vector(int length)
    Construct the zero vector of the given length.
    protected
    GF2Vector(int[] v, int length)
    Construct a new GF2Vector of the given length and with the given element array.
     
    GF2Vector(int length, int[] v)
    Construct a GF2Vector of the given length and with elements from the given array.
     
    GF2Vector(int length, int t, SecureRandom sr)
    Construct a random GF2Vector of the given length with the specified number of non-zero coefficients.
     
    GF2Vector(int length, SecureRandom sr)
    Construct a random GF2Vector of the given length.
     
    Copy constructor.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    add(Vector other)
    Adds another GF2Vector to this vector.
    boolean
    equals(Object other)
    Check if the given object is equal to this vector.
    Return a new vector consisting of the first k elements of this vector.
    Return a new vector consisting of the last k elements of this vector.
    extractVector(int[] setJ)
    Return a new vector consisting of the elements of this vector with the indices given by the set setJ.
    int
    getBit(int index)
    Return the value of the bit of this vector at the specified index.
    byte[]
    Encode this vector as byte array.
    int
    Return the Hamming weight of this vector, i.e., compute the number of units of this vector.
    int[]
     
    int
     
    boolean
    Return whether this is the zero vector (i.e., all elements are zero).
    Multiply this vector with a permutation.
    static GF2Vector
    OS2VP(int length, byte[] encVec)
    Construct a new GF2Vector with the given length out of the encoded vector.
    void
    setBit(int index)
    Set the coefficient at the given index to 1.
    Rewrite this vector as a vector over GF(2m) with t elements.
     

    Methods inherited from class org.bouncycastle.pqc.legacy.math.linearalgebra.Vector Link icon

    getLength

    Methods inherited from class java.lang.Object Link icon

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • GF2Vector Link icon

      public GF2Vector(int length)
      Construct the zero vector of the given length.
      Parameters:
      length - the length of the vector
    • GF2Vector Link icon

      public GF2Vector(int length, SecureRandom sr)
      Construct a random GF2Vector of the given length.
      Parameters:
      length - the length of the vector
      sr - the source of randomness
    • GF2Vector Link icon

      public GF2Vector(int length, int t, SecureRandom sr)
      Construct a random GF2Vector of the given length with the specified number of non-zero coefficients.
      Parameters:
      length - the length of the vector
      t - the number of non-zero coefficients
      sr - the source of randomness
    • GF2Vector Link icon

      public GF2Vector(int length, int[] v)
      Construct a GF2Vector of the given length and with elements from the given array. The array is copied and unused bits are masked out.
      Parameters:
      length - the length of the vector
      v - the element array
    • GF2Vector Link icon

      public GF2Vector(GF2Vector other)
      Copy constructor.
      Parameters:
      other - another GF2Vector
    • GF2Vector Link icon

      protected GF2Vector(int[] v, int length)
      Construct a new GF2Vector of the given length and with the given element array. The array is not changed and only a reference to the array is stored. No length checking is performed either.
      Parameters:
      v - the element array
      length - the length of the vector
  • Method Details Link icon

    • OS2VP Link icon

      public static GF2Vector OS2VP(int length, byte[] encVec)
      Construct a new GF2Vector with the given length out of the encoded vector.
      Parameters:
      length - the length of the vector
      encVec - the encoded vector
      Returns:
      the decoded vector
    • getEncoded Link icon

      public byte[] getEncoded()
      Encode this vector as byte array.
      Specified by:
      getEncoded in class Vector
      Returns:
      the encoded vector
    • getVecArray Link icon

      public int[] getVecArray()
      Returns:
      the int array representation of this vector
    • getHammingWeight Link icon

      public int getHammingWeight()
      Return the Hamming weight of this vector, i.e., compute the number of units of this vector.
      Returns:
      the Hamming weight of this vector
    • isZero Link icon

      public boolean isZero()
      Description copied from class: Vector
      Return whether this is the zero vector (i.e., all elements are zero).
      Specified by:
      isZero in class Vector
      Returns:
      whether this is the zero vector (i.e., all elements are zero)
    • getBit Link icon

      public int getBit(int index)
      Return the value of the bit of this vector at the specified index.
      Parameters:
      index - the index
      Returns:
      the value of the bit (0 or 1)
    • setBit Link icon

      public void setBit(int index)
      Set the coefficient at the given index to 1. If the index is out of bounds, do nothing.
      Parameters:
      index - the index of the coefficient to set
    • add Link icon

      public Vector add(Vector other)
      Adds another GF2Vector to this vector.
      Specified by:
      add in class Vector
      Parameters:
      other - another GF2Vector
      Returns:
      this + other
      Throws:
      ArithmeticException - if the other vector is not a GF2Vector or has another length.
    • multiply Link icon

      public Vector multiply(Permutation p)
      Multiply this vector with a permutation.
      Specified by:
      multiply in class Vector
      Parameters:
      p - the permutation
      Returns:
      this*p = p*this
    • extractVector Link icon

      public GF2Vector extractVector(int[] setJ)
      Return a new vector consisting of the elements of this vector with the indices given by the set setJ.
      Parameters:
      setJ - the set of indices of elements to extract
      Returns:
      the new GF2Vector [this_setJ[0], this_setJ[1], ..., this_setJ[#setJ-1]]
    • extractLeftVector Link icon

      public GF2Vector extractLeftVector(int k)
      Return a new vector consisting of the first k elements of this vector.
      Parameters:
      k - the number of elements to extract
      Returns:
      a new GF2Vector consisting of the first k elements of this vector
    • extractRightVector Link icon

      public GF2Vector extractRightVector(int k)
      Return a new vector consisting of the last k elements of this vector.
      Parameters:
      k - the number of elements to extract
      Returns:
      a new GF2Vector consisting of the last k elements of this vector
    • toExtensionFieldVector Link icon

      public GF2mVector toExtensionFieldVector(GF2mField field)
      Rewrite this vector as a vector over GF(2m) with t elements.
      Parameters:
      field - the finite field GF(2m)
      Returns:
      the converted vector over GF(2m)
    • equals Link icon

      public boolean equals(Object other)
      Check if the given object is equal to this vector.
      Specified by:
      equals in class Vector
      Parameters:
      other - vector
      Returns:
      the result of the comparison
    • hashCode Link icon

      public int hashCode()
      Specified by:
      hashCode in class Vector
      Returns:
      the hash code of this vector
    • toString Link icon

      public String toString()
      Specified by:
      toString in class Vector
      Returns:
      a human readable form of this vector