http://hg.viff.dk/viff/rev/dea34098e8fb
changeset: 1111:dea34098e8fb
user:      Tord Reistad <[email protected]>
date:      Fri Mar 06 12:03:08 2009 +0100
summary:   Added xor for field elements of type GF.

diffstat:

1 file changed, 24 insertions(+)
viff/field.py |   24 ++++++++++++++++++++++++

diffs (48 lines):

diff -r 24d0ffe14c3a -r dea34098e8fb viff/field.py
--- a/viff/field.py     Thu Mar 05 21:17:10 2009 +0100
+++ b/viff/field.py     Fri Mar 06 12:03:08 2009 +0100
@@ -32,6 +32,7 @@
 
 >>> x = Zp(10)
 >>> y = Zp(15)
+>>> z = Zp(1)
 
 Addition and subtraction (with modulo reduction):
 
@@ -40,6 +41,15 @@
 >>> x - y
 {14}
 
+Bitwise xor for field elements:
+
+>>> z ^ z
+{0}
+>>> z ^ 0
+{1}
+>>> 1 ^ z
+{0}
+
 Exponentiation:
 
 >>> x**3
@@ -397,6 +407,20 @@
             """Subtraction (reflected argument version)."""
             return GFElement(other - self.value)
 
+        def __xor__(self, other):
+            """Xor for bitvalues."""
+            if not isinstance(other, (GFElement, int, long)):
+                return NotImplemented
+            try:
+                assert self.field is other.field, "Fields must be identical"
+                return GFElement(self.value ^ other.value)
+            except AttributeError:
+                return GFElement(self.value ^ other)
+
+        def __rxor__(self, other):
+            """Xor for bitvalues (reflected argument version)."""
+            return GFElement(other ^ self.value)
+
         def __mul__(self, other):
             """Multiplication."""
             if not isinstance(other, (GFElement, int, long)):
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk

Reply via email to