fix: Fix dff algorithm attempt
This commit is contained in:
parent
b54753fe7e
commit
d599292d3a
3 changed files with 9 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::usize;
|
||||
|
||||
use num::{pow::Pow, traits::ToBytes, BigUint, FromPrimitive};
|
||||
use num::{cast::AsPrimitive, pow::Pow, traits::ToBytes, BigUint, FromPrimitive};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::poly::{gcd, Polynomial};
|
||||
|
|
@ -13,25 +13,30 @@ pub struct Factors {
|
|||
|
||||
pub fn ddf(f: Polynomial) -> Vec<(Polynomial, u128)> {
|
||||
let q = BigUint::pow(&BigUint::from_u8(2).unwrap(), 128);
|
||||
eprintln!("q: {:?}", q);
|
||||
|
||||
let mut z: Vec<(Polynomial, u128)> = vec![];
|
||||
let mut d: u128 = 1;
|
||||
let mut f_star = f.clone();
|
||||
|
||||
let one_cmp = Polynomial::one();
|
||||
while f_star.degree() >= (2 * d) as usize {
|
||||
while f_star.degree() as u128 >= (d) {
|
||||
let h = Polynomial::x().bpow_mod(q.clone().pow(d), f_star.clone()) + Polynomial::x();
|
||||
|
||||
let g = gcd(&h, &f_star);
|
||||
if g != one_cmp {
|
||||
eprintln!("d is: {}", d);
|
||||
eprintln!("g is: {:?}", &g.clone().to_c_array());
|
||||
|
||||
z.push((g.clone(), d));
|
||||
f_star = f_star.div(&g).0;
|
||||
}
|
||||
eprintln!("d outer is: {}", d);
|
||||
eprintln!("F star degree is {:?}", &f_star.degree());
|
||||
|
||||
d += 1;
|
||||
}
|
||||
if f_star != one_cmp {
|
||||
eprintln!("fstar not one");
|
||||
z.push((f_star.clone(), f_star.degree() as u128));
|
||||
} else if z.len() == 0 {
|
||||
z.push((f.clone(), 1));
|
||||
|
|
|
|||
|
|
@ -180,10 +180,7 @@ impl BitXor for FieldElement {
|
|||
impl Div for FieldElement {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: Self) -> Self::Output {
|
||||
eprintln!("RHS in div{:02X?}", &rhs);
|
||||
|
||||
let inverse = rhs.inv();
|
||||
eprintln!("Inverse in div{:02X?}", inverse);
|
||||
self.clone() * inverse
|
||||
}
|
||||
}
|
||||
|
|
@ -202,15 +199,11 @@ impl Div for &FieldElement {
|
|||
impl PartialOrd for FieldElement {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
for (byte_a, byte_b) in self.as_ref().iter().rev().zip(other.as_ref().iter().rev()) {
|
||||
eprintln!("Field Partial Ord Bytes: {:02X} {:02X}", byte_a, byte_b);
|
||||
if byte_a > byte_b {
|
||||
eprintln!("Bytes were greater");
|
||||
return Some(Ordering::Greater);
|
||||
} else if byte_a < byte_b {
|
||||
eprintln!("Bytes were less");
|
||||
return Some(Ordering::Less);
|
||||
} else {
|
||||
eprintln!("Bytes were equal");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -231,15 +224,11 @@ impl Eq for FieldElement {
|
|||
impl Ord for FieldElement {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
for (byte_a, byte_b) in self.as_ref().iter().rev().zip(other.as_ref().iter().rev()) {
|
||||
eprintln!("Field Ord Bytes: {:02X} {:02X}", byte_a, byte_b);
|
||||
if byte_a > byte_b {
|
||||
eprintln!("Bytes were greater");
|
||||
return Ordering::Greater;
|
||||
} else if byte_a < byte_b {
|
||||
eprintln!("Bytes were less");
|
||||
return Ordering::Less;
|
||||
} else {
|
||||
eprintln!("Bytes were equal");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,8 +177,6 @@ impl Polynomial {
|
|||
exponent >>= 1;
|
||||
}
|
||||
|
||||
eprintln!("result in powmod before reduction: {:02X?}", result);
|
||||
|
||||
while !result.polynomial.is_empty()
|
||||
&& result
|
||||
.polynomial
|
||||
|
|
@ -191,8 +189,6 @@ impl Polynomial {
|
|||
result.polynomial.pop();
|
||||
}
|
||||
|
||||
eprintln!("result in powmod after reduction: {:02X?}", result);
|
||||
|
||||
if result.is_empty() {
|
||||
result = Polynomial::new(vec![FieldElement::new(vec![0; 16])]);
|
||||
}
|
||||
|
|
@ -262,7 +258,7 @@ impl Polynomial {
|
|||
pub fn div(&self, rhs: &Self) -> (Self, Self) {
|
||||
// Div by zero check ommitted since data is guaranteed to be non 0
|
||||
|
||||
eprintln!("{:?}, {:?}", self.polynomial.len(), rhs.polynomial.len());
|
||||
//eprintln!("{:?}, {:?}", self.polynomial.len(), rhs.polynomial.len());
|
||||
|
||||
if self.polynomial.len() < rhs.polynomial.len() {
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue