Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from random import randint
- from gcd import egcd
- from math import sqrt
- def prime(n):
- if n <=1:
- return False
- if n % 2 == 0:
- if n == 2:
- return True
- else:
- return False
- i = 3
- while i <= sqrt(n):
- if n % i == 0:
- return False
- i += 2
- return True
- def inversa(e, n):
- (gcd,tmp,d) = egcd(e, n)
- if not gcd == 1:
- return None
- else:
- return (tmp+n) %n
- def rprime(digits):
- minimum = 10**(digits-1)
- maximum = minimum * 10 - 1
- while True:
- r = randint(minimum,maximum)
- if prime(r):
- return r
- def checkgen(n,mod):
- t = 1
- c = 0
- while not t == 1 or c == 0:
- t = (t*n) % mod
- c+=1
- if c == mod:
- break
- if c == mod - 1:
- return True
- else:
- return False
- def findgen(mod):
- while True:
- cand = randint(2,mod -1)
- if checkgen(cand,mod):
- return cand
- def pickone(mod):
- return randint(2,mod-1)
- def potmod(x, pot, mod):
- bits = pot
- pot
- res = 1
- temp = x
- while bits > 0:
- if bits %2 == 1:
- res = (res * temp % mod)
- temp = (temp * temp) % mod
- bits = bits >> 1
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement