[viff-devel] How to convert field elements to integers?

Martin Geisler mg at daimi.au.dk
Thu Jan 22 07:57:08 PST 2009


Tord Ingolf Reistad <tordr at stud.ntnu.no> writes:

Hi Tord

> I have a simple question: After completing a VIFF program I have
> opened the shares and gotten the results, but the results are field
> elements (probably elements of class GFElement), how do I turn them
> back into integers?

You just access the value attribute of your GFElement: x.value. If you
update to the very latest version of VIFF you can now also use int(x)
to do the same.

> The documentation says nothing about how to turn them back into
> integers, which should be essencial if I am going to use these
> shares in other applications. There seems to be some code __repr__
> in GFElements, but I cannot see how I can use it.

That method is called when x is a field element and you do

  "foo %r bar" % x

or

  repr(x)

It just produces a string with the value.

> As an additional problem, the integers should not be integers in the
> set form 0 to p-1, but integers from -(p-1)/2 to +(p-1)/2. How
> should one do that efficiently?

That should be as simple as

  x.value - (x.modulus - 1) // 2

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.


More information about the viff-devel mailing list