Skip to content

Instantly share code, notes, and snippets.

Created Nov 19, 2016
What would you like to do?
Calculate size of groups in modular exponentiation
from __future__ import print_function
import sys
import getopt
import math
g = None
m = None
argv = sys.argv[1:]
opts, args = getopt.getopt(argv, "m:")
for opt, arg in opts:
if opt == '-m':
m = int(arg)
raise Exception("Unrecognised option: {0}".format(opt))
if args:
raise Exception("Not matching options: {0}".format(args))
if m < 1:
raise Exception("Must specify -m, must be positive integer")
print("Groups modulo {0}".format(m))
for g in range(m):
group_el = []
for e in range(m+1):
val = pow(g, e, m)
if val in group_el:
print('g: {0:>{width}}, {1}'.format(g, group_el,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment