encryption working independently of theta
This commit is contained in:
@ -8,3 +8,6 @@ edition = "2021"
|
||||
[dependencies]
|
||||
rand = "0.9.1"
|
||||
rug = "1.27.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rayon = "1.10.0"
|
||||
|
@ -40,10 +40,13 @@ pub fn encrypt_bit_asym(m: u8, pk: &PublicKey, rho: u32) -> Integer {
|
||||
let mut rng = StdRng::from_os_rng();
|
||||
let x0 = &pk.xs[0];
|
||||
|
||||
let num_keys = &pk.xs.len();
|
||||
let proba: f64 = 2f64 / (*num_keys as f64);
|
||||
|
||||
// random x_i
|
||||
let mut sum = Integer::from(0);
|
||||
for x in pk.xs.iter().skip(1) {
|
||||
if rng.random_bool(0.1) {
|
||||
if rng.random_bool(proba) {
|
||||
sum += x;
|
||||
}
|
||||
}
|
||||
@ -84,18 +87,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_encrypt_decrypt_bit() {
|
||||
use rayon::prelude::*;
|
||||
|
||||
let eta: u32 = 10000;
|
||||
let gamma: u32 = 11000;
|
||||
let theta: usize = 20;
|
||||
let theta: usize = 50;
|
||||
let rho: u32 = 128;
|
||||
|
||||
for _ in 0..=255 {
|
||||
(0..=127).into_par_iter().for_each(|_| {
|
||||
let (sk, pk) = generate_keys(gamma, eta, rho, theta);
|
||||
for &m in &[0u8, 1u8] {
|
||||
let c = encrypt_bit_asym(m, &pk, rho);
|
||||
let m2 = decrypt_bit(&c, &sk.p);
|
||||
assert_eq!(m, m2);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user