Package viff :: Module field :: Class GF256
[hide private]
[frames] | no frames]

Class GF256

source code


Models an element of the GF(2^8) field.
Nested Classes [hide private]
  field
Models an element of the GF(2^8) field.
Instance Methods [hide private]
 
__init__(self, value)
Initialize new element.
source code
 
__add__(self, other)
Add this and another GF256 element.
source code
 
__radd__(self, other)
Add this and another number (reflected argument version).
source code
 
__sub__(self, other)
Subtract this and another GF256 element.
source code
 
__rsub__(self, other)
Subtract this and another GF256 element (reflected argument version).
source code
 
__xor__(self, other)
Exclusive-or.
source code
 
__rxor__(self, other)
Exclusive-or (reflected argument version).
source code
 
__mul__(self, other)
Multiply this and another GF256.
source code
 
__rmul__(self, other)
Multiply this and another number (reflected argument version).
source code
 
__pow__(self, exponent)
Exponentiation.
source code
 
__div__(self, other)
Division.
source code
 
__truediv__(self, other)
Division.
source code
 
__floordiv__(self, other)
Division.
source code
 
__rdiv__(self, other)
Division (reflected argument version).
source code
 
__rtruediv__(self, other)
Division (reflected argument version).
source code
 
__rfloordiv__(self, other)
Division (reflected argument version).
source code
 
__neg__(self)
Negation.
source code
 
__invert__(self)
Invertion.
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
__eq__(self, other)
Equality testing.
source code
 
__ne__(self, other)
Inequality testing.
source code
 
__hash__(self)
Hash value.
source code
 
__nonzero__(self)
Truth value testing.
source code

Inherited from FieldElement: __int__, __long__, split

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variables [hide private]
  modulus = 256
GF(2^8) modulus, always 256.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, value)
(Constructor)

source code 

Initialize new element.

The value given is modulo reduced so the following holds:

>>> GF256(1) == GF256(257)
True
Overrides: object.__init__

__add__(self, other)
(Addition operator)

source code 

Add this and another GF256 element.

>>> GF256(0x01) + GF256(0x01)
[0]
>>> GF256(0x01) + GF256(0x02)
[3]

Adding integers works too, the other operand is coerced into a GF256 element automatically:

>>> GF256(0x01) + 1
[0]

__radd__(self, other)
(Right-side addition operator)

source code 

Add this and another number (reflected argument version).

other is not Share, otherwise Share.__add__() would have been called, and other is not a GF256, otherwise GF256.__add__() would have been called.

__sub__(self, other)
(Subtraction operator)

source code 

Subtract this and another GF256 element.

Addition is its own inverse in GF(2^8) and so this is the same as __add__.

__rsub__(self, other)

source code 
Subtract this and another GF256 element (reflected argument version).

__xor__(self, other)
(Exclusive-Or operator)

source code 

Exclusive-or.

This is just addition for GF256 elements.

__rxor__(self, other)

source code 
Exclusive-or (reflected argument version).

__rmul__(self, other)

source code 

Multiply this and another number (reflected argument version).

other is not Share, otherwise Share.__mul__() would have been called, and other is not a GF256, otherwise GF256.__mul__() would have been called.

__invert__(self)

source code 

Invertion.

Raises ZeroDivisionError if trying to inverse the zero element.

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__eq__(self, other)
(Equality operator)

source code 

Equality testing.

Testing for equality with integers works as expected:

>>> GF256(10) == 10
True

__hash__(self)
(Hashing function)

source code 
Hash value.
Overrides: object.__hash__

__nonzero__(self)
(Boolean test operator)

source code 

Truth value testing.

Returns False if this element is zero, True otherwise. This allows GF256 elements to be used directly in Boolean formula:

>>> bool(GF256(0))
False
>>> bool(GF256(1))
True
>>> x = GF256(1)
>>> not x
False