Skip to content

Commit ebd9336

Browse files
committed
no homo
1 parent 122c060 commit ebd9336

File tree

3 files changed

+62
-16
lines changed

3 files changed

+62
-16
lines changed

homo/fhe_image.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ void dct_blocks(std::vector<std::vector<double>> &blocks) {
307307
for (int a = 0; a < blocks.size(); a++) {
308308
dct(&blocks[a][0]);
309309
}
310+
}
311+
312+
void print_parameters(const SEALContext &context) {
313+
std::cout << "/ Encryption parameters:" << std::endl;
314+
std::cout << "| poly_modulus: " << context.poly_modulus().to_string() << std::endl;
315+
316+
/*
317+
Print the size of the true (product) coefficient modulus
318+
*/
319+
std::cout << "| coeff_modulus size: "
320+
<< context.total_coeff_modulus().significant_bit_count() << " bits" << std::endl;
321+
322+
std::cout << "| plain_modulus: " << context.plain_modulus().value() << std::endl;
323+
std::cout << "\\ noise_standard_deviation: " << context.noise_standard_deviation() << std::endl;
324+
std::cout << std::endl;
310325
}
311326

312327
#endif

homo/raymond.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const std::vector<double> S_STD_LUM_QUANT = { 16,11,12,14,12,10,16,14,13,14,18,1
2525
const std::vector<double> S_STD_CROMA_QUANT = { 17,18,18,24,21,24,47,26,26,47,99,66,56,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99 };
2626

2727
void raymond_average();
28-
void print_parameters(const SEALContext &context);
2928

3029

3130
int main()
@@ -170,18 +169,3 @@ void raymond_average() {
170169

171170
return;
172171
}
173-
174-
void print_parameters(const SEALContext &context) {
175-
std::cout << "/ Encryption parameters:" << std::endl;
176-
std::cout << "| poly_modulus: " << context.poly_modulus().to_string() << std::endl;
177-
178-
/*
179-
Print the size of the true (product) coefficient modulus
180-
*/
181-
std::cout << "| coeff_modulus size: "
182-
<< context.total_coeff_modulus().significant_bit_count() << " bits" << std::endl;
183-
184-
std::cout << "| plain_modulus: " << context.plain_modulus().value() << std::endl;
185-
std::cout << "\\ noise_standard_deviation: " << context.noise_standard_deviation() << std::endl;
186-
std::cout << std::endl;
187-
}

homo/sender.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,52 @@ int main()
1919
uint8_t *image_data = stbi_load(test_filename, &width, &height, &actual_composition, requested_composition);
2020
std::cout << width << " x " << height << std::endl;
2121
print_image(image_data, width, height);
22+
23+
24+
// Encryption Parameters
25+
EncryptionParameters params;
26+
params.set_poly_modulus("1x^32768 + 1");
27+
params.set_coeff_modulus(coeff_modulus_128(2048));
28+
params.set_plain_modulus(1 << 14);
29+
SEALContext context(params);
30+
print_parameters(context);
31+
32+
33+
// Generate keys
34+
start = std::chrono::steady_clock::now();
35+
KeyGenerator keygen(context);
36+
auto public_key = keygen.public_key();
37+
auto secret_key = keygen.secret_key();
38+
auto diff = std::chrono::steady_clock::now() - start;
39+
std::cout << "KeyGen: ";
40+
std::cout << chrono::duration<double, milli>(diff).count() << " ms" << std::endl;
41+
42+
// Encrytor and decryptor setup
43+
Encryptor encryptor(context, public_key);
44+
Evaluator evaluator(context);
45+
Decryptor decryptor(context, secret_key);
46+
47+
// Base + Number of coefficients used for encoding past the decimal point (both pos and neg)
48+
// Example: if poly_base = 11, and N_FRACTIONAL_COEFFS=3, then we will have
49+
// a1 * 11^-1 + a2 * 11^-2 + a3 * 11^-3
50+
const int POLY_BASE = 11;
51+
const int N_FRACTIONAL_COEFFS = 3;
52+
const int N_NUMBER_COEFFS = 10;
53+
54+
FractionalEncoder encoder(context.plain_modulus(), context.poly_modulus(), N_NUMBER_COEFFS, N_FRACTIONAL_COEFFS, POLY_BASE);
55+
56+
std::ofstream myfile;
57+
myfile.open("../image/nothingpersonnel.txt");
58+
start = std::chrono::steady_clock::now();
59+
for (int i = 0; i < width * height; i++) {
60+
Ciphertext c;
61+
double conv = (double)(image_data[i]);
62+
std::cout<< conv <<std::endl;
63+
encryptor.encrypt(encoder.encode(conv), c);
64+
c.save(myfile);
65+
}
66+
67+
68+
myfile.close();
2269
return 0;
2370
}

0 commit comments

Comments
 (0)