def testEncryptDecryptRegression(self):
     logging.debug('Running testEncryptDecryptRegression method.')
     paillier1 = paillier.Paillier(None, 6497955158, 126869, 31536, 53022)
     ciphertext = paillier1.Encrypt(10100, 74384)
     self.assertEquals(848742150, ciphertext)
     decryption = paillier1.Decrypt(848742150)
     self.assertEquals(10100, decryption)
 def __init__(self, key):
   super(HomomorphicFloatCipher, self).__init__()
   self._paillier = pcrypto.Paillier(key)
   # Store raw binary nsquare as a string using '\x' syntax which can be passed
   # in a query.
   nsquare_bytes = number.LongToBytes(self._paillier.nsquare)
   self.nsquare = '\\x' + '\\x'.join(x.encode('hex') for x in nsquare_bytes)
Example #3
0
    def setup_keys(self, key_length=1024):
        with Timer(logstring="    Key generation") as t:
            self.p = paillier.Paillier(key_length=1024)
        self.benchmarks['c_key_generate'] = (t.secs, 0, t.mem)

        with Timer(logstring="    Key upload") as t:
            snd_bytes = self.peer.send(self.p.pubkey)
        self.benchmarks['c_key_upload'] = (t.secs, snd_bytes, t.mem)
Example #4
0
 def setup_keys(self):
     pubkey = self.peer.recv()
     self.P = paillier.Paillier(pubkey=pubkey)
#!/usr/bin/env python
#
# Copyright 2012 Google Inc. All Rights Reserved.
"""Unitttest for pallier module."""

from google.apputils import app
import logging
from google.apputils import basetest as googletest

import paillier

_KEY1 = '0123456789abcdef'
_PAILLIER1 = paillier.Paillier(_KEY1)


class PaillierTest(googletest.TestCase):
    def testInitRegression(self):
        logging.debug('Running testInitRegression method.')
        self.assertEquals(
            '1540446301194064289812749522269230895547727566172905280'
            '2882838764869064995301252386388711882490727734617556022'
            '8507897723047251274539138292573162215487167555658392777'
            '9536049058356061700336746251128024825735763630561361861'
            '0929443937044092979781080225804474709639217360215385238'
            '4570204894053081599875939643724669', str(_PAILLIER1.n))
        self.assertEquals(
            '2372974806862473835834144917018834556331926303125038409'
            '6775811412153106981342389782378239488788122287676159276'
            '1850386996821190664988405870356206273587971863611766912'
            '0381062564616153635414185469585083583071508506707445513'
            '2001434085731328421552649684032869139250221416966312123'