modred fix failures

This commit is contained in:
Christoph J. Scherr 2023-05-16 14:23:05 +02:00
parent 853c28a4d5
commit 08fcef7079
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
1 changed files with 8 additions and 10 deletions

View File

@ -26,21 +26,19 @@ pub fn modred(mut poly: u64, relation: u64, verbose: bool) -> Result<u64, String
println!("polynomial:\t0x{:x}\t", poly); println!("polynomial:\t0x{:x}\t", poly);
println!("======================================================================="); println!("=======================================================================");
} }
while relation.leading_zeros() - poly.leading_zeros() != 0 { if relation > poly {
diffrence = relation.leading_zeros() - poly.leading_zeros();
poly = poly ^ (relation << diffrence);
if verbose { if verbose {
println!("{index}:\tpoly: 0x{:x}\t", poly); println!("relation is longer than polynom, nothing to do.");
//println!("{index}:\tpoly: 0b{:b}\t", poly); }
} return Ok(poly);
index += 1; }
} while poly > relation {
// one more time! diffrence = relation.leading_zeros() - poly.leading_zeros();
diffrence = relation.leading_zeros() - poly.leading_zeros(); poly = poly ^ (relation << diffrence);
poly = poly ^ (relation << diffrence); if verbose {
if verbose { println!("{index}:\tpoly: 0x{:x}\t 0b{:b}", poly, poly);
println!("{index}:\tpoly: 0x{:x}\t", poly); }
//println!("{index}:\tpoly: 0b{:b}\t", poly); index += 1;
} }
return Ok(poly); return Ok(poly);
} }