http://hg.viff.dk/viff/rev/e5aecd62cf67
changeset: 1108:e5aecd62cf67
user: Tord Reistad <[email protected]>
date: Thu Mar 05 13:23:42 2009 +0100
summary: Splits FieldElement into array of bits LSB first.
diffstat:
1 file changed, 18 insertions(+)
viff/field.py | 18 ++++++++++++++++++
diffs (35 lines):
diff -r 88ac6ac5fe70 -r e5aecd62cf67 viff/field.py
--- a/viff/field.py Thu Mar 05 13:00:59 2009 +0100
+++ b/viff/field.py Thu Mar 05 13:23:42 2009 +0100
@@ -69,6 +69,7 @@
from gmpy import mpz
+from math import log, ceil
class FieldElement(object):
@@ -84,6 +85,23 @@
__long__ = __int__
+ def split(self):
+ """Splits self into bit array LSB first.
+
+ >>> Zp = GF(29)
+ >>> Zp(3).split()
+ [1, 1, 0, 0, 0]
+ >>> Zp(28).split()
+ [0, 0, 1, 1, 1]
+ """
+ length = int(ceil(log(self.modulus,2)))
+ result = [0] * length
+ temp = self.value
+ for i in range(length):
+ result[i] = temp % 2
+ temp = temp // 2
+ return result
+
#: Inversion table.
#:
#: Maps a value *x* to *x^-1*. See `_generate_tables`.
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk