viff

changeset 1010:c9775d9bd895

Fake FieldElement class for benchmark purposes.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 06 Nov 2008 14:25:17 +0100
parents 3d9eb7e148f9
children 80ba4bffd726
files viff/field.py
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/viff/field.py	Thu Nov 06 14:25:14 2008 +0100
     1.2 +++ b/viff/field.py	Thu Nov 06 14:25:17 2008 +0100
     1.3 @@ -514,6 +514,30 @@
     1.4      _field_cache[modulus] = GFElement
     1.5      return GFElement
     1.6  
     1.7 +class FakeFieldElement(FieldElement):
     1.8 +    def __init__(self, value):
     1.9 +        # We store the value passed in order to make the objects take
    1.10 +        # up some meomry space.
    1.11 +        self.value = value
    1.12 +
    1.13 +    __add__ = __radd__ = __sub__ = __rsub__ \
    1.14 +        = __mul__ = __rmul__ = __div__ = __rdiv__ \
    1.15 +        = __truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ \
    1.16 +        = __pow__ = __neg__ \
    1.17 +        = lambda self, other: FakeFieldElement(1)
    1.18 +
    1.19 +    __invert__ = sqrt = lambda self: FakeFieldElement(1)
    1.20 +
    1.21 +    bit = lambda self, index: 1
    1.22 +
    1.23 +    __repr__ = __str__ = lambda self: "{{%d}}" % self.value
    1.24 +
    1.25 +FakeFieldElement.field = FakeFieldElement
    1.26 +# Fix the modulus to a fairly large number -- this is used in various
    1.27 +# places when protocols want to generate a random element from the
    1.28 +# interval {0, 1, ..., modulus-1}.
    1.29 +FakeFieldElement.modulus = 987654321
    1.30 +
    1.31  
    1.32  if __name__ == "__main__":
    1.33      import doctest    #pragma NO COVER