Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(enc_vector1 + plain_vector1) not equal to enc(vector1 + vector1) #462

Open
HaonanYuan opened this issue Nov 6, 2023 · 0 comments
Open
Labels
Type: Question ❔ Question about implementation or some technical aspect

Comments

@HaonanYuan
Copy link

Question

(enc_vector1 + plain_vector1) not equal to enc(vector1 + vector1)

Further Information

I am trying to calculate an encrypted vector mul plain matrix, and this encrypted vector is equal to an encrypted vector add a plain vector. However, I find there is a wired thing that (Enc(a) + b).mm(User_B) is not equal to Enc(a + b).mm(User_B). The test code is shown below.

Screenshots

plain_matrix = np.array([[0.0, 0.0, 0.0, 0.0],
                         [0.0, 0.0, 0.0, 0.0],
                         [0.0, 0.0, 0.0, 0.0],
                         [0.0, 10.0, 0.0, 0.0]])

plain_vector = np.array([0.1, 237874.552365, 0.000000002, 1])
plain_vector_1 = np.array([0.1, 237874.552365, 0.000000002, 1])

plain_res = np.dot(plain_matrix, plain_vector + plain_vector_1)

enc_vector = ts.ckks_vector(context, plain_vector)
enc_vector_1 = ts.ckks_vector(context, plain_vector_1)

enc_vector_2 = enc_vector + enc_vector_1
enc_vector_3 = enc_vector + plain_vector_1

enc_res_1 = enc_vector_2.mm(plain_matrix.T)
enc_res_2 = enc_vector_3.mm(plain_matrix.T)

res_1 = enc_res_1.decrypt()
res_2 = enc_res_2.decrypt()

print(plain_res)
print(res_1)
print(res_2)

result

[ 0. 0. 0. 4757491.0473]
[2.655831578605229e-10, -5.912459528628605e-10, -1.994569202300637e-09, 4757497.852951228]
[6.590880511287327e-10, 3.316680605596568e-09, -2.8285272646509907e-09, 2378748.926475601]

@HaonanYuan HaonanYuan added the Type: Question ❔ Question about implementation or some technical aspect label Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question ❔ Question about implementation or some technical aspect
Projects
None yet
Development

No branches or pull requests

1 participant