From d494db52169b68a4c423f3cba8c3cb016a9247be Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 3 Jun 2023 19:41:41 +0200 Subject: [PATCH] gallois calc order of an element --- src/math/gallois.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/math/gallois.rs b/src/math/gallois.rs index 7dd9a83..3709c31 100644 --- a/src/math/gallois.rs +++ b/src/math/gallois.rs @@ -15,7 +15,7 @@ /// License: MIT /// Source: -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 { + 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]