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.

Revisions

  1. reloadedd created this gist May 6, 2020.
    53 changes: 53 additions & 0 deletions equation_solver.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/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()