Top Description Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.linearalgebra

public Class Permutation

extends Object
Class Inheritance
Imports
java.security.SecureRandom, org.bouncycastle.util.Arrays

This class implements permutations of the set {0,1,...,n-1} for some given n > 0, i.e., ordered sequences containing each number m (0 <= m < n) once and only once.

Field Summary

Modifier and TypeField and Description
private int[]
perm

perm holds the elements of the permutation vector, i.e. [perm(0), perm(1), ..., perm(n-1)]

Constructor Summary

AccessConstructor and Description
public
Permutation(int
the size of the permutation
n
)

Create the identity permutation of the given size.

public
Permutation(int[]
the permutation vector
perm
)

Create a permutation using the given permutation vector.

public
Permutation(byte[]
the encoded permutation
enc
)

Create a permutation from an encoded permutation.

public
Permutation(int
the size of the permutation
n
,
SecureRandom
the source of randomness
sr
)

Create a random permutation of the given size.

Method Summary

Modifier and TypeMethod and Description
public Permutation

Returns:

this-1
computeInverse
()

Compute the inverse permutation P-1.

public boolean

Returns:

true or false
equals
(Object
- permutation
other
)

Overrides java.lang.Object.equals.

checks if given object is equal to this permutation.
public byte[]

Returns:

the encoded permutation
getEncoded
()

Encode this permutation as byte array.

public int[]

Returns:

the permutation vector (perm(0),perm(1),...,perm(n-1))
getVector
()

public int

Returns:

the hash code of this permutation
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private boolean

Returns:

true if perm represents an n-permutation and false otherwise
isPermutation
(int[]
permutation vector
perm
)

Check that the given array corresponds to a permutation of the set {0, 1, ..., n-1}.

public Permutation

Returns:

this * p
rightMultiply
(Permutation
the other permutation
p
)

Compute the product of this permutation and another permutation.

public String

Returns:

a human readable form of the permutation
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

permback to summary
private int[] perm

perm holds the elements of the permutation vector, i.e. [perm(0), perm(1), ..., perm(n-1)]

Constructor Detail

Permutationback to summary
public Permutation(int n)

Create the identity permutation of the given size.

Parameters
n:int

the size of the permutation

Permutationback to summary
public Permutation(int[] perm)

Create a permutation using the given permutation vector.

Parameters
perm:int[]

the permutation vector

Permutationback to summary
public Permutation(byte[] enc)

Create a permutation from an encoded permutation.

Parameters
enc:byte[]

the encoded permutation

Permutationback to summary
public Permutation(int n, SecureRandom sr)

Create a random permutation of the given size.

Parameters
n:int

the size of the permutation

sr:SecureRandom

the source of randomness

Method Detail

computeInverseback to summary
public Permutation computeInverse()

Compute the inverse permutation P-1.

Returns:Permutation

this-1

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

checks if given object is equal to this permutation.

The method returns false whenever the given object is not permutation.

Parameters
other:Object

- permutation

Returns:boolean

true or false

getEncodedback to summary
public byte[] getEncoded()

Encode this permutation as byte array.

Returns:byte[]

the encoded permutation

getVectorback to summary
public int[] getVector()
Returns:int[]

the permutation vector (perm(0),perm(1),...,perm(n-1))

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

the hash code of this permutation

isPermutationback to summary
private boolean isPermutation(int[] perm)

Check that the given array corresponds to a permutation of the set {0, 1, ..., n-1}.

Parameters
perm:int[]

permutation vector

Returns:boolean

true if perm represents an n-permutation and false otherwise

rightMultiplyback to summary
public Permutation rightMultiply(Permutation p)

Compute the product of this permutation and another permutation.

Parameters
p:Permutation

the other permutation

Returns:Permutation

this * p

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a human readable form of the permutation