I want to do a inverse operation on a mpz_t
type number. I see we have int mpz_invert(mpz_t rop, const mpz_t op1, const mpz_t op2)
function, which only gives inverse of (op1 % op2). How can I just get inverse of op1 (mpz_t
) ?
Asked
Active
Viewed 677 times
-2
-
Can you give an example of what you call *inverse*, what type and value it should have? – Marc Glisse Aug 18 '18 at 08:01
-
I'm looking for (mpz_t)^-1 or (1/mpz_t) – katik Aug 18 '18 at 12:01
-
1I really don't think you are. `mpz_t` is an **integer** type. In integer arithmetic, the value of `1 / n` is zero for any value of `n` except 0, 1 and -1. Is that really what you want? Also, what on earth does this have to do with cryptography? Please try harder to explain what you're doing. – r3mainer Aug 18 '18 at 15:58
1 Answers
1
mpz_invert()
is a modular arithmetic function. It calculates the modular multiplicative inverse of an integer (i.e., the value that you have to multiply it by to obtain a value that is congruent to 1 in the given modulus). The value of this inverse (and even its very existence) depends on the value of the modulus you choose.
If you just want to calculate the value of 1 divided by some number, then you shouldn't be using integers. Use rational (type mpq_t
) or floating point (type mpf_t
) values instead.

r3mainer
- 23,981
- 3
- 51
- 88