Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def GCD(a,b):
- if a == 0:
- return b
- if b == 0:
- return a
- if a < b:
- return GCD(a,b%a)
- else:
- return GCD(a%b,b)
- def ord(n,r):
- val = GCD(n,r)
- if val != 1:
- print("error: not co-prime.", val)
- return 0
- value = n
- k = 1
- while value != 1:
- value *= n
- value = value%r
- k += 1
- return k
- def multexp(terms, exp, modpoly, reduce):
- prev = terms[:]
- while exp > 1:
- axillary = [0]*(len(prev)+len(terms)-1)
- for i in range(0, len(terms)):
- for j in range(0, len(prev)):
- axillary[i+j] += terms[i]*prev[j]
- print(axillary)
- for i in range(0,len(axillary)-len(modpoly)+1):
- temp = axillary[i]
- for j in range(0,len(modpoly)):
- axillary[j+i] -= modpoly[j]*temp
- print(axillary)
- for i in range(0,len(axillary)):
- axillary[i] = axillary[i]%reduce
- while axillary[0] == 0:
- axillary.pop(0)
- prev = axillary[:]
- exp -= 1
- return prev
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement