Fixed some comments, removed some useless code
This commit is contained in:
parent
535a49bad9
commit
310e3b3b2a
16
main.py
16
main.py
|
@ -37,7 +37,7 @@ def extendedEuclid(a, b):
|
||||||
def modInv(a, m):
|
def modInv(a, m):
|
||||||
"""returns the multiplicative inverse of a in modulo m as a
|
"""returns the multiplicative inverse of a in modulo m as a
|
||||||
positive value between zero and m-1"""
|
positive value between zero and m-1"""
|
||||||
# notice that a and m need to co-prime to each other.
|
# notice that a and m need to be co-prime to each other.
|
||||||
if coPrime([a, m]):
|
if coPrime([a, m]):
|
||||||
linearCombination = extendedEuclid(a, m)
|
linearCombination = extendedEuclid(a, m)
|
||||||
return linearCombination[1] % m
|
return linearCombination[1] % m
|
||||||
|
@ -58,18 +58,6 @@ def extractTwos(m):
|
||||||
return i, m >> i
|
return i, m >> i
|
||||||
|
|
||||||
|
|
||||||
def int2baseTwo(x):
|
|
||||||
"""x is a positive integer. Convert it to base two as a list of integers
|
|
||||||
in reverse order as a list."""
|
|
||||||
# repeating x >>= 1 and x & 1 will do the trick
|
|
||||||
assert x >= 0
|
|
||||||
bitInverse = []
|
|
||||||
while x != 0:
|
|
||||||
bitInverse.append(x & 1)
|
|
||||||
x >>= 1
|
|
||||||
return bitInverse
|
|
||||||
|
|
||||||
|
|
||||||
def millerRabin(n, k):
|
def millerRabin(n, k):
|
||||||
"""
|
"""
|
||||||
Miller Rabin pseudo-prime test
|
Miller Rabin pseudo-prime test
|
||||||
|
@ -169,7 +157,7 @@ def decrypt(secret, modN, d, blockSize):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
n, e, d = newKey(10 ** 100, 10 ** 101, 50)
|
n, e, d = newKey(2**40, 2 ** 41, 20)
|
||||||
message = 35274764
|
message = 35274764
|
||||||
|
|
||||||
print("original message is {}".format(message))
|
print("original message is {}".format(message))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user