http://hg.viff.dk/viff/rev/b44882c6d4f6
changeset: 1180:b44882c6d4f6
user:      Marcel Keller <[email protected]>
date:      Wed May 13 16:38:16 2009 +0200
summary:   Reduce number of isinstance() calls.

diffstat:

1 file changed, 17 insertions(+), 6 deletions(-)
viff/field.py |   23 +++++++++++++++++------

diffs (54 lines):

diff -r cbc39e56b402 -r b44882c6d4f6 viff/field.py
--- a/viff/field.py     Wed May 13 15:32:00 2009 +0200
+++ b/viff/field.py     Wed May 13 16:38:16 2009 +0200
@@ -168,16 +168,21 @@
             other = other.value
         return GF256(self.value ^ other)
 
-    #: Add this and another GF256 element (reflected argument version).
-    __radd__ = __add__
+    def __radd__(self, other):
+        """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."""
+        return GF256(self.value ^ other)
+    
     #: Subtract this and another GF256 element.
     #:
     #: Addition is its own inverse in GF(2^8) and so this is the same
     #: as `__add__`.
     __sub__ = __add__
     #: Subtract this and another GF256 element (reflected argument version).
-    __rsub__ = __sub__
+    __rsub__ = __radd__
 
     #: Exclusive-or.
     #:
@@ -185,7 +190,7 @@
     __xor__ = __add__
 
     #: Exclusive-or (reflected argument version).
-    __rxor__ = __xor__
+    __rxor__ = __radd__
 
     def __mul__(self, other):
         """Multiply this and another GF256.
@@ -204,8 +209,14 @@
         return _mul_table[(self.value, other)]
 
 
-    #: Multiply this and another GF256 element (reflected argument version).
-    __rmul__ = __mul__
+    def __rmul__(self, other):
+        """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."""
+        return _mul_table[(self.value, other)]
 
     def __pow__(self, exponent):
         """Exponentiation."""
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk

Reply via email to