de.flexiprovider.common.math.finitefields
Class GFPElement

java.lang.Object
  |
  +--de.flexiprovider.common.math.finitefields.GFPElement
All Implemented Interfaces:
GFElement

public class GFPElement
extends java.lang.Object
implements GFElement

This class implements an element of the finite field GF(p), where p is a large prime.

Author:
Birgit Henhapl, Martin Döring
See Also:
GF2nElement, GFPElement

Constructor Summary
GFPElement(byte[] encValue, FlexiBigInt p)
          Create a new GFPElement from the given encoded value and field order.
GFPElement(FlexiBigInt value, FlexiBigInt p)
          Create a new GFPElement from the given value and field order.
GFPElement(GFPElement other)
          Copy constructor.
 
Method Summary
 GFElement add(GFElement addend)
          Compute the sum of this element and addend.
 void addToThis(GFElement addend)
          Compute this + addend (overwrite this).
 java.lang.Object clone()
           
 boolean equals(java.lang.Object other)
          Compare this element with another object.
 int hashCode()
           
 GFElement invert()
          Compute the multiplicative inverse of this element.
 boolean isOne()
          Checks whether this element is one.
 boolean isZero()
          Checks whether this element is zero.
 GFElement multiply(GFElement factor)
          Compute the product of this element and factor.
 void multiplyThisBy(GFElement factor)
          Compute this * factor (overwrite this).
 GFPElement negate()
          Compute the additive inverse of this element.
static GFPElement ONE(FlexiBigInt p)
          Create the one element.
 GFElement subtract(GFElement minuend)
          Compute the difference of this element and minuend.
 void subtractFromThis(GFElement minuend)
          Compute the difference of this element and minuend, overwriting this element.
 byte[] toByteArray()
          Returns this element as byte array.
 FlexiBigInt toFlexiBigInt()
          Returns this element as FlexiBigInt.
 java.lang.String toString()
          Return a String representation of this element.
 java.lang.String toString(int radix)
          Return a String representation of this element.
static GFPElement ZERO(FlexiBigInt p)
          Create the zero element.
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GFPElement

public GFPElement(FlexiBigInt value,
                  FlexiBigInt p)
Create a new GFPElement from the given value and field order.
Parameters:
value - the value
p - the order of the field

GFPElement

public GFPElement(byte[] encValue,
                  FlexiBigInt p)
Create a new GFPElement from the given encoded value and field order.
Parameters:
encValue - the encoded value
p - the order of the field

GFPElement

public GFPElement(GFPElement other)
Copy constructor.
Parameters:
other - another GFPElement
Method Detail

clone

public java.lang.Object clone()
Specified by:
clone in interface GFElement
Overrides:
clone in class java.lang.Object
Returns:
a copy of this GFPElement

ZERO

public static GFPElement ZERO(FlexiBigInt p)
Create the zero element.
Parameters:
p - the modulus
Returns:
the zero element in GF(p)

ONE

public static GFPElement ONE(FlexiBigInt p)
Create the one element.
Parameters:
p - the modulus
Returns:
the one element in GF(p)

isZero

public boolean isZero()
Checks whether this element is zero.
Specified by:
isZero in interface GFElement
Returns:
true if this is the zero element

isOne

public boolean isOne()
Checks whether this element is one.
Specified by:
isOne in interface GFElement
Returns:
true if this is the one element

equals

public boolean equals(java.lang.Object other)
Compare this element with another object.
Specified by:
equals in interface GFElement
Overrides:
equals in class java.lang.Object
Parameters:
other - the other object
Returns:
true if the two objects are equal, false otherwise

hashCode

public int hashCode()
Specified by:
hashCode in interface GFElement
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this element

add

public GFElement add(GFElement addend)
              throws DifferentFieldsException
Compute the sum of this element and addend.
Specified by:
add in interface GFElement
Parameters:
addend - the addend
Returns:
this + other (newly created)
Throws:
DifferentFieldsException - if the elements are of different fields.

addToThis

public void addToThis(GFElement addend)
               throws DifferentFieldsException
Compute this + addend (overwrite this).
Specified by:
addToThis in interface GFElement
Parameters:
addend - the addend
Throws:
DifferentFieldsException - if the elements are of different fields.

subtract

public GFElement subtract(GFElement minuend)
                   throws DifferentFieldsException
Compute the difference of this element and minuend.
Specified by:
subtract in interface GFElement
Parameters:
minuend - the minuend
Returns:
this - minuend (newly created)
Throws:
DifferentFieldsException - if the elements are of different fields.

subtractFromThis

public void subtractFromThis(GFElement minuend)
                      throws DifferentFieldsException
Compute the difference of this element and minuend, overwriting this element.
Specified by:
subtractFromThis in interface GFElement
Parameters:
minuend - the minuend
Throws:
DifferentFieldsException - if the elements are of different fields.

negate

public GFPElement negate()
Compute the additive inverse of this element.
Returns:
-this (newly created)

multiply

public GFElement multiply(GFElement factor)
                   throws DifferentFieldsException
Compute the product of this element and factor.
Specified by:
multiply in interface GFElement
Parameters:
factor - the factor
Returns:
this * factor (newly created)
Throws:
DifferentFieldsException - if the elements are of different fields.

multiplyThisBy

public void multiplyThisBy(GFElement factor)
                    throws DifferentFieldsException
Compute this * factor (overwrite this).
Specified by:
multiplyThisBy in interface GFElement
Parameters:
factor - the factor
Throws:
DifferentFieldsException - if the elements are of different fields.

invert

public GFElement invert()
                 throws java.lang.ArithmeticException
Compute the multiplicative inverse of this element.
Specified by:
invert in interface GFElement
Returns:
this-1 (newly created)
Throws:
java.lang.ArithmeticException - if this is the zero element.

toByteArray

public byte[] toByteArray()
Description copied from interface: GFElement
Returns this element as byte array. The conversion is P1363-conform.
Specified by:
toByteArray in interface GFElement
Returns:
this element as byte array

toFlexiBigInt

public FlexiBigInt toFlexiBigInt()
Description copied from interface: GFElement
Returns this element as FlexiBigInt. The conversion is P1363-conform.
Specified by:
toFlexiBigInt in interface GFElement
Returns:
this element as FlexiBigInt

toString

public java.lang.String toString()
Description copied from interface: GFElement
Return a String representation of this element.
Specified by:
toString in interface GFElement
Overrides:
toString in class java.lang.Object
Returns:
a human readable form of this element

toString

public java.lang.String toString(int radix)
Description copied from interface: GFElement
Return a String representation of this element. radix specifies the radix of the String representation.
Specified by:
toString in interface GFElement
Following copied from interface: de.flexiprovider.common.math.finitefields.GFElement
Parameters:
radix - specifies the radix of the String representation
Returns:
String representation of this element with the specified radix