def test():
    sk = SecretKey(500, 2.44e-5, 1024, 2, 10, 3.73e-9, 8, 2, 2.44e-5)
    ck = CloudKey(sk)
    p = np.random.binomial(1, 0.5)
    x = tlweSymEncrypt((p * 2 + -1) * (2**-3), sk.params.alpha, sk.key.trlwe)
    y = IdentityKeySwitch(x, ck)
    np.set_printoptions(threshold=2000)
    if p != tlweSymDecrypt(y, sk.key.tlwe):
        print(p)
        print(tlweSymDecrypt(y, sk.key.tlwe))
        print(i)
        exit()
Example #2
0
def test():
    sk = SecretKey(500, 2.44e-5, 1024, 2, 10, 3.73e-9, 8, 2, 2.44e-5)
    ck = CloudKey(sk)
    pa = np.random.binomial(1, 0.5)
    pb = np.random.binomial(1, 0.5)
    ca = tlweSymEncrypt((pa * 2 + -1) * (2**-3), sk.params.alpha, sk.key.tlwe)
    cb = tlweSymEncrypt((pb * 2 + -1) * (2**-3), sk.params.alpha, sk.key.tlwe)
    res = HomNAND(ca, cb, ck)
    y = tlweSymDecrypt(res, sk.key.tlwe)
    np.set_printoptions(threshold=2000)
    if (pa & pb) ^ 1 != y:
        print("FAILED")
        print(
            tlweSymDecrypt(
                np.uint32(np.append(np.zeros(ck.params.n), 2**29)) - ca - cb,
                sk.key.tlwe))
        print(y)
        exit()
from pyFHE.trlwe import trlweSymEncrypt, trlweSymDecrypt
from pyFHE.trgsw import trgswfftSymEncrypt, trgswfftExternalProduct
from pyFHE.key import SecretKey
from pyFHE.utils import dtot32
import numpy as np

np.set_printoptions(threshold=2000)
for i in range(100):
    sk = SecretKey(500, 2**(-7), 1024, 2, 10, 3.73e-9, 8, 2, 2.43e-5)
    x = trlweSymEncrypt(np.full(sk.params.N, 2**-3), sk.params.alpha,
                        sk.key.trlwe, sk.params.twist)
    A = trgswfftSymEncrypt(np.append([1], np.zeros(sk.params.N - 1)),
                           sk.params.bkalpha, sk.params.h, sk.key.trlwe,
                           sk.params.twist)
    y = trgswfftExternalProduct(A, x, sk.params)
    if np.sum(trlweSymDecrypt(y, sk.key.trlwe, sk.params.twist)) != len(y[0]):
        print(sk.params.decb)
        print(trlweSymDecrypt(y, sk.key.trlwe, sk.params.twist))
        print(np.uint32(y))
        print(i)
        break
Example #4
0
from pyFHE.detwfa import CMUXFFT
from pyFHE.trgsw import trgswfftSymEncrypt
from pyFHE.trlwe import trlweSymEncrypt, trlweSymDecrypt
from pyFHE.key import SecretKey
import numpy as np

np.set_printoptions(threshold=2000)
for i in range(1000):
    sk = SecretKey(500, 2.44e-5, 1024, 2, 10, 3.73e-9, 8, 8, 2.44e-5)
    p0 = np.random.randint(0, 2, size=sk.params.N, dtype=np.uint32)
    p1 = np.random.randint(0, 2, size=sk.params.N, dtype=np.uint32)
    d0 = trlweSymEncrypt((2 * p0 - 1) * 2**-3, sk.params.alpha, sk.key.trlwe,
                         sk.params.twist)
    d1 = trlweSymEncrypt((2 * p1 - 1) * 2**-3, sk.params.alpha, sk.key.trlwe,
                         sk.params.twist)
    c = np.random.randint(0, 2)
    CFFT = trgswfftSymEncrypt(np.append([c], np.zeros(sk.params.N - 1)),
                              sk.params.bkalpha, sk.params.h, sk.key.trlwe,
                              sk.params.twist)
    y = trlweSymDecrypt(CMUXFFT(CFFT, d1, d0, sk.params), sk.key.trlwe,
                        sk.params.twist)
    if np.any(c * (p1 - p0) + p0 != y):
        print(i)
        print(p0)
        print(p1)
        print(c)
        print(c * (p1 - p0) + p0)
        print(y)
        break
Example #5
0
from pyFHE.trlwe import trlweSymEncrypt, trlweSymDecrypt, SampleExtractIndex
from pyFHE.tlwe import tlweSymDecrypt
from pyFHE.key import SecretKey
import numpy as np

sk = SecretKey(500, 2**(-9), 2, 2, 512, 2**(-27))
c = trlweSymEncrypt(np.array([2**-3, -2**-3]), 2**(-24), sk.key.trlwe,
                    sk.params.twist)
print(tlweSymDecrypt(SampleExtractIndex(c, 0), sk.key.trlwe))
print(tlweSymDecrypt(SampleExtractIndex(c, 1), sk.key.trlwe))