viff

changeset 1180:b44882c6d4f6

Reduce number of isinstance() calls.
author Marcel Keller <mkeller@cs.au.dk>
date Wed, 13 May 2009 16:38:16 +0200
parents cbc39e56b402
children 3171ea9886cb
files viff/field.py
diffstat 1 files changed, 17 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/viff/field.py	Wed May 13 15:32:00 2009 +0200
     1.2 +++ b/viff/field.py	Wed May 13 16:38:16 2009 +0200
     1.3 @@ -168,16 +168,21 @@
     1.4              other = other.value
     1.5          return GF256(self.value ^ other)
     1.6  
     1.7 -    #: Add this and another GF256 element (reflected argument version).
     1.8 -    __radd__ = __add__
     1.9 +    def __radd__(self, other):
    1.10 +        """Add this and another number (reflected argument version).
    1.11  
    1.12 +        other is not Share, otherwise Share.__add__() would have been
    1.13 +        called, and other is not a GF256, otherwise GF256.__add__()
    1.14 +        would have been called."""
    1.15 +        return GF256(self.value ^ other)
    1.16 +    
    1.17      #: Subtract this and another GF256 element.
    1.18      #:
    1.19      #: Addition is its own inverse in GF(2^8) and so this is the same
    1.20      #: as `__add__`.
    1.21      __sub__ = __add__
    1.22      #: Subtract this and another GF256 element (reflected argument version).
    1.23 -    __rsub__ = __sub__
    1.24 +    __rsub__ = __radd__
    1.25  
    1.26      #: Exclusive-or.
    1.27      #:
    1.28 @@ -185,7 +190,7 @@
    1.29      __xor__ = __add__
    1.30  
    1.31      #: Exclusive-or (reflected argument version).
    1.32 -    __rxor__ = __xor__
    1.33 +    __rxor__ = __radd__
    1.34  
    1.35      def __mul__(self, other):
    1.36          """Multiply this and another GF256.
    1.37 @@ -204,8 +209,14 @@
    1.38          return _mul_table[(self.value, other)]
    1.39  
    1.40  
    1.41 -    #: Multiply this and another GF256 element (reflected argument version).
    1.42 -    __rmul__ = __mul__
    1.43 +    def __rmul__(self, other):
    1.44 +        """Multiply this and another number (reflected argument
    1.45 +        version).
    1.46 +
    1.47 +        other is not Share, otherwise Share.__mul__() would have been
    1.48 +        called, and other is not a GF256, otherwise GF256.__mul__()
    1.49 +        would have been called."""
    1.50 +        return _mul_table[(self.value, other)]
    1.51  
    1.52      def __pow__(self, exponent):
    1.53          """Exponentiation."""