mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
GitHub Action formats our code with psf/black (#1569)
* GitHub Action formats our code with psf/black @poyea Your review please. * fixup! Format Python code with psf/black push
This commit is contained in:
@@ -41,19 +41,21 @@ def miller_rabin(n, allow_probable=False):
|
||||
"A return value of True indicates a probable prime."
|
||||
)
|
||||
# array bounds provided by analysis
|
||||
bounds = [2_047,
|
||||
1_373_653,
|
||||
25_326_001,
|
||||
3_215_031_751,
|
||||
2_152_302_898_747,
|
||||
3_474_749_660_383,
|
||||
341_550_071_728_321,
|
||||
1,
|
||||
3_825_123_056_546_413_051,
|
||||
1,
|
||||
1,
|
||||
318_665_857_834_031_151_167_461,
|
||||
3_317_044_064_679_887_385_961_981]
|
||||
bounds = [
|
||||
2_047,
|
||||
1_373_653,
|
||||
25_326_001,
|
||||
3_215_031_751,
|
||||
2_152_302_898_747,
|
||||
3_474_749_660_383,
|
||||
341_550_071_728_321,
|
||||
1,
|
||||
3_825_123_056_546_413_051,
|
||||
1,
|
||||
1,
|
||||
318_665_857_834_031_151_167_461,
|
||||
3_317_044_064_679_887_385_961_981,
|
||||
]
|
||||
|
||||
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
|
||||
for idx, _p in enumerate(bounds, 1):
|
||||
@@ -131,5 +133,5 @@ def test_miller_rabin():
|
||||
# upper limit for probabilistic test
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_miller_rabin()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
def find_primitive(n):
|
||||
for r in range(1, n):
|
||||
li = []
|
||||
for x in range(n-1):
|
||||
val = pow(r,x,n)
|
||||
for x in range(n - 1):
|
||||
val = pow(r, x, n)
|
||||
if val in li:
|
||||
break
|
||||
li.append(val)
|
||||
@@ -11,16 +11,15 @@ def find_primitive(n):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
q = int(input('Enter a prime number q: '))
|
||||
q = int(input("Enter a prime number q: "))
|
||||
a = find_primitive(q)
|
||||
a_private = int(input('Enter private key of A: '))
|
||||
a_private = int(input("Enter private key of A: "))
|
||||
a_public = pow(a, a_private, q)
|
||||
b_private = int(input('Enter private key of B: '))
|
||||
b_private = int(input("Enter private key of B: "))
|
||||
b_public = pow(a, b_private, q)
|
||||
|
||||
a_secret = pow(b_public, a_private, q)
|
||||
b_secret = pow(a_public, b_private, q)
|
||||
|
||||
print('The key value generated by A is: ', a_secret)
|
||||
print('The key value generated by B is: ', b_secret)
|
||||
|
||||
print("The key value generated by A is: ", a_secret)
|
||||
print("The key value generated by B is: ", b_secret)
|
||||
|
||||
Reference in New Issue
Block a user