Skip to content

Commit 9d84bf4

Browse files
author
Anusha-DeviE
committed
Replace asserts with explicit validation in modular_division
1 parent 03c60a1 commit 9d84bf4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

maths/modular_division.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ def modular_division(a: int, b: int, n: int) -> int:
2828
4
2929
3030
"""
31-
assert n > 1
32-
assert a > 0
33-
assert greatest_common_divisor(a, n) == 1
31+
if n <= 1:
32+
raise ValueError("Modulus n must be greater than 1")
33+
if a <= 0:
34+
raise ValueError("Divisor a must be a positive integer")
35+
if greatest_common_divisor(a, n) != 1:
36+
raise ValueError("a and n must be coprime (gcd(a, n) = 1)")
37+
3438
(_d, _t, s) = extended_gcd(n, a) # Implemented below
3539
x = (b * s) % n
3640
return x

0 commit comments

Comments
 (0)