43 lines
1.0 KiB
Rust
43 lines
1.0 KiB
Rust
use rug::Integer;
|
||
use crate::matrix::Matrix;
|
||
use lll_rs::lll::biglll;
|
||
mod lll;
|
||
mod matrix;
|
||
|
||
fn main() {
|
||
// 1. Build lattice matrix basis
|
||
let ciphertexts = vec![
|
||
Integer::from(37459),
|
||
Integer::from(8227),
|
||
Integer::from(44119),
|
||
Integer::from(22575),
|
||
Integer::from(9249),
|
||
Integer::from(38483),
|
||
Integer::from(26181),
|
||
];
|
||
let noise_bits = 2;
|
||
let basis_matrix = Matrix::new_lattice(noise_bits, ciphertexts.clone()).unwrap();
|
||
|
||
println!("matrix: {:?}", basis_matrix);
|
||
|
||
// 2. reduce with LLL
|
||
let mut lll_matrix = basis_matrix.to_lll_matrix();
|
||
biglll::lattice_reduce(&mut lll_matrix);
|
||
|
||
// 3. Extract shortest vector
|
||
let shortest_vector = &lll_matrix[0];
|
||
println!("Shortest vector: {:?}", shortest_vector);
|
||
|
||
// 4. q0 candidate
|
||
let q0 = &shortest_vector[0] / (Integer::from(1) << (noise_bits + 1));
|
||
|
||
// 5. Find p
|
||
// compute r0 = x0 (mod q0)
|
||
// and p = (x0 − r0)/q0.
|
||
let x0 = &ciphertexts[0];
|
||
let r0 = x0 % q0.clone();
|
||
let p_guess = (x0 - r0) / q0;
|
||
|
||
println!("Recovered p: {}", p_guess);
|
||
}
|