The `modInverse` method calculates the modular multiplicative inverse of a big integer modulo a given modulus.
The syntax of BigInt.modInverse() method is:
BigInt modInverse(BigInt modulus)
This modInverse() method of BigInt returns the modular multiplicative inverse of this big integer modulo modulus
.
Parameter | Optional/Required | Description |
---|---|---|
modulus | required | the modulus to calculate the modular multiplicative inverse with |
BigInt.modInverse() returns value of type BigInt
.
In this example,
num
, initialized with 7.modulus
, initialized with 11.modInverse
method to calculate the modular multiplicative inverse of num
modulo modulus
.void main() {
BigInt num = BigInt.from(7);
BigInt modulus = BigInt.from(11);
BigInt inverse = num.modInverse(modulus);
print('Modular inverse of 7 modulo 11: $inverse');
}
Modular inverse of 7 modulo 11: 8
In this example,
num
, initialized with 25.modulus
, initialized with 8.modInverse
method to calculate the modular multiplicative inverse of num
modulo modulus
.void main() {
BigInt num = BigInt.from(25);
BigInt modulus = BigInt.from(8);
BigInt inverse = num.modInverse(modulus);
print('Modular inverse of 25 modulo 8: $inverse');
}
Modular inverse of 25 modulo 8: 1
In this example,
num
, initialized with 11.modulus
, initialized with 13.modInverse
method to calculate the modular multiplicative inverse of num
modulo modulus
.void main() {
BigInt num = BigInt.from(11);
BigInt modulus = BigInt.from(13);
BigInt inverse = num.modInverse(modulus);
print('Modular inverse of 11 modulo 13: $inverse');
}
Modular inverse of 11 modulo 13: 6
In this Dart tutorial, we learned about modInverse() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.