From 34ab20c9825662edb46a0a2f66b71bf13fcafde7 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sun, 18 May 2025 23:01:41 +0200 Subject: [PATCH] agcd print update --- .gitignore | 2 ++ src/agcd.rs | 7 +++++++ 2 files changed, 9 insertions(+) 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 }