More comments

This commit is contained in:
Sarah Jamie Lewis 2021-08-14 11:11:32 -07:00
parent 3540f29ae2
commit 64fef1848c
1 changed files with 22 additions and 16 deletions

View File

@ -97,30 +97,28 @@ impl Solver {
/// Solve the system and return the indexes of the true hashes (or error if the system is unsolvable)
pub fn attempt_solve(&self) -> Result<Vec<usize>, ()> {
// Arrange the hashes into an augmented for matrix...
let mut orginal_matrix = Matrix::new(
(self.synthetic_max + self.threshold) as usize,
self.expanded_hashes.len(),
);
let mut augmented_matrix = Matrix::new(
(self.synthetic_max + self.threshold) as usize + self.expanded_hashes.len(),
self.expanded_hashes.len(),
);
let m = (self.synthetic_max + self.threshold) as usize;
let mut augmented_matrix = Matrix::new(
m + self.expanded_hashes.len(),
self.expanded_hashes.len(),
);
for j in 0..self.expanded_hashes.len() {
for i in 0..m {
augmented_matrix.update(i, j, self.expanded_hashes[j as usize].0[i as usize]);
orginal_matrix.update(i, j, self.expanded_hashes[j as usize].0[i as usize])
}
}
// Append the identity matrix...
for (i, r) in (m..m + self.expanded_hashes.len()).enumerate() {
augmented_matrix.update(r as usize, i, PrimeOrderDomain::new(1));
}
// Transpose for row reduction...
augmented_matrix = augmented_matrix.transpose();
// Pretty Print...
for i in 0..augmented_matrix.rows() {
for j in 0..augmented_matrix.cols() {
print!("{} ", augmented_matrix.at(i, j as usize));
@ -128,6 +126,7 @@ impl Solver {
println!(";")
}
// Do the actual row reduction...
let cols = augmented_matrix.cols();
let rows = augmented_matrix.rows();
@ -160,11 +159,15 @@ impl Solver {
}
}
println!("");
println!("");
println!("");
println!();
println!();
println!();
// Transpose back to column form...
augmented_matrix = augmented_matrix.transpose();
// Pretty Print for checking...
for i in 0..augmented_matrix.rows() {
for j in 0..augmented_matrix.cols() {
print!("{} ", augmented_matrix.at(i, j as usize));
@ -175,7 +178,8 @@ impl Solver {
}
}
// Calculate the Nulls...
// Calculate the Kernel Basis Vectors...these are the columns where the
// Original matrix is now all 0s
let mut count = 0;
for col in (0..self.expanded_hashes.len()).rev() {
let mut is_null = true;
@ -193,9 +197,11 @@ impl Solver {
}
if count == 0 {
// Unsolvable...
return Err(());
}
// We found some vectors...now we can derive a solution...
println!("Found {} Kernel Basis Vectors...", count);
let mut solution = vec![];