Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add roots of unity to FQ class #156

Open
HarryR opened this issue Aug 19, 2019 · 0 comments
Open

Add roots of unity to FQ class #156

HarryR opened this issue Aug 19, 2019 · 0 comments
Labels
enhancement New feature or request
Projects

Comments

@HarryR
Copy link
Owner

HarryR commented Aug 19, 2019

So we can do something like FQ(...).primitive_root(5) which will return a primitive 5th root of unity in the field.

There are situations where there may not be a n-th root of unity, an exception should be thrown.

It may also be beneficial to do a deterministic search for the roots of unity, so that the results are consistent across runs.

Example code:

def find_root(p, n):
	x = randint(1, p-1)
	return pow(x, (p-1)//n, p)

def find_roots(p, n):
	# https://crypto.stackexchange.com/questions/63614/finding-the-n-th-root-of-unity-in-a-finite-field
	# In particular, if N is a power of 2 and ω^(N/2) = −1, then ω is a principal N-th root of unity.
	gs = set()
	while len(gs) != n:
		gs.add(find_root(p, n))
	return list(gs)

def is_primitive_root(g, p, n):
	return pow(g, n//2, p) != 1

def primitive_roots(p, n):
	return [_ for _ in find_roots(p, n) if is_primitive_root(_, p, n)]

def primitive_root(p, n):
	while True:
		g = find_root(p, n)
		if is_primitive_root(g, p, n):
			return g
@HarryR HarryR added this to To Do in 2019 via automation Aug 19, 2019
@HarryR HarryR added the enhancement New feature or request label Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
2019
  
To Do
Development

No branches or pull requests

1 participant