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 #2
0
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**(-7),1024,2,1024,3.73e-9,8,2,2.43e-5)
    p = np.random.randint(0,2,size = sk.params.N,dtype = np.uint32)
    c = trlweSymEncrypt((2*p-1)*2**-3,sk.params.alpha,sk.key.trlwe,sk.params.twist)
    y = trlweSymDecrypt(c,sk.key.trlwe,sk.params.twist)
    if np.any(p != y):
        print(i)
        print (trlweSymDecrypt(c,sk.key.trlwe,sk.params.twist))
        break
Example #3
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 #4
0
from pyFHE.trgsw import Decomposition
from pyFHE.trlwe import trlweSymEncrypt, trlweSymDecrypt
from pyFHE.key import SecretKey
from pyFHE.utils import dtot32
import numpy as np

for i in range(1000):
    sk = SecretKey(500, 2**(-7), 1024, 2, 1024, 3.73e-9, 8, 2, 2.43e-5)
    p = np.random.randint(0, 2, size=sk.params.N, dtype=np.uint32)
    c = trlweSymEncrypt((2 * p - 1) * 2**-3, sk.params.alpha, sk.key.trlwe,
                        sk.params.twist)
    cdec = Decomposition(c, sk.params)
    print(np.int32(cdec))
    h = dtot32(sk.params.h)
    rec = np.array(
        [cdec[0] * h[0] + cdec[1] * h[1], cdec[2] * h[0] + cdec[3] * h[1]])
    if np.any(trlweSymDecrypt(rec, sk.key.trlwe, sk.params.twist) != p):
        print(i)
        break