gallois calc order of an element

This commit is contained in:
Christoph J. Scherr 2023-06-03 19:41:41 +02:00
parent d454bde3c3
commit d494db5216
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
1 changed files with 14 additions and 1 deletions

View File

@ -15,7 +15,7 @@
/// License: MIT
/// Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
use crate::{math::modexp, cplex::printing::seperator, math::modred::modred};
use crate::{math::modexp::{self, modular_exponentiation_wrapper}, cplex::printing::seperator, math::modred::modred};
use core::fmt;
@ -379,6 +379,19 @@ impl GalloisField {
self.cha = i;
return i;
}
/// calculate the order of a element
pub fn calc_ord(self, n: u128) -> Option<u128> {
if n == 0 {
return None;
}
for ord in 2..self.base {
if self.pow(n, ord) == 1 {
return Some(ord);
}
}
panic!("No order was found, but n is not 0 and all possibilities have been tried");
}
}
#[pymethods]