Skip to content

Commit

Permalink
Group element subgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
czechbol committed May 6, 2021
1 parent e185580 commit fd9336a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mathcrypto/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ def get_element_order(self, element) -> int:
s.add(int(gmpy2.powmod(element, exp, self.mod)))
return len(s)

def get_element_subgroup(self, element) -> int:
"""Gets the subgroup of any element in the group
Args:
element (int): Element of the group
Raises:
ValueError: When the ``element`` does not belong to the group
Returns:
list: Returns the order of ``element`` in the group
"""

if element not in self.elements:
raise ValueError
if element in self.generators:
return self.order

s = set()
for exp in range(len(self.elements)):
s.add(int(gmpy2.powmod(element, exp, self.mod)))
return list(s)

def get_inverse_element(self, element: int) -> int:
"""Gets the inverse to an element in the group
Expand Down

0 comments on commit fd9336a

Please sign in to comment.