diff --git a/.gitignore b/.gitignore index 9be143b..394e172 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target scripts/__pycache__/ +*.txt +Cargo.lock diff --git a/src/agcd.rs b/src/agcd.rs index cf712ec..522ffd7 100644 --- a/src/agcd.rs +++ b/src/agcd.rs @@ -21,6 +21,11 @@ pub fn agcd(ciphertexts: Vec, noise_bits: usize) -> Integer { let q0 = &shortest_vector[0] / (Integer::from(1) << (noise_bits + 1)); println!("q0: {}", q0); + if q0 == 0 { + println!("Couldn't recover p."); + return Integer::from(0); + } + // 5. Find p // compute r0 = x0 (mod q0) // and p = (x0 − r0)/q0. @@ -31,5 +36,7 @@ pub fn agcd(ciphertexts: Vec, noise_bits: usize) -> Integer { let p_guess = abs((x0 - r0) / q0); println!("Recovered p: {}", p_guess); + println!("Approximate GCD with noise_bits={}: {}", noise_bits, p_guess); + p_guess }