changeset 1065:47fce60972ae

Easy integer coercion for FieldElement objects.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 22 Jan 2009 16:55:22 +0100
parents 8bca4980563f
children 9f176022087d
files doc/field.txt viff/field.py
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/field.txt	Thu Jan 08 11:31:57 2009 +0100
+++ b/doc/field.txt	Thu Jan 22 16:55:22 2009 +0100
@@ -7,7 +7,8 @@
    .. autoclass:: FieldElement
 
    .. autoclass:: GF256
-      :members: __add__, __mul__, __pow__, __div__, __neg__, __invert__, __eq__, __nonzero__
+      :members: __add__, __mul__, __pow__, __div__, __neg__,
+                __invert__, __eq__, __nonzero__, __int__
 
       .. attribute:: GF256.modulus
 
--- a/viff/field.py	Thu Jan 08 11:31:57 2009 +0100
+++ b/viff/field.py	Thu Jan 22 16:55:22 2009 +0100
@@ -74,6 +74,15 @@
 class FieldElement(object):
     """Common base class for elements."""
 
+    def __int__(self):
+        """Extract integer value from the field element.
+
+        >>> int(GF256(10))
+        10
+        """
+        return self.value
+
+    __long__ = __int__
 
 #: Inversion table.
 #: