Skip to content

Instantly share code, notes, and snippets.

@reloadedd
Created May 6, 2020 18:07
Show Gist options
  • Select an option

  • Save reloadedd/e3c19cd6b42d0088f4549704d25fef25 to your computer and use it in GitHub Desktop.

Select an option

Save reloadedd/e3c19cd6b42d0088f4549704d25fef25 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
def solve_equation(a, m, totient):
k = 1
result = a ** k % m
while result != 1 and k <= totient:
k += 1
result = a ** k % m
if k != totient:
return 0
# print(f'\t => ordinul lui {a} modulo {m} = {k}')
return totient
def main():
if len(sys.argv) != 4:
print(f'Usage: {sys.argv[0]} m totient totient_de_totient')
exit(0)
try:
m = int(sys.argv[1])
except ValueError:
print(f'Boss, de cand "{sys.argv[1]}"" e numar la tine?')
exit(0)
try:
totient = int(sys.argv[2])
except ValueError:
print(f'Boss, de cand "{sys.argv[2]}" e numar la tine?')
exit(0)
try:
totient2 = int(sys.argv[3])
except ValueError:
print(f'Boss, de cand "{sys.argv[3]}" e numar la tine?')
exit(0)
a = 1
k = 0
radacini = []
while k != totient2:
if solve_equation(a, m, totient) != 0:
print(f'\t => ordinul lui {a} modulo {m} = {totient}')
k += 1
radacini.append(a)
a += 1
print(f'Radacinile primitive modulo {m}, care sunt in numar de {totient2}, sunt:\n{radacini}')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment