Skip to content
Advertisement

Extend Euclid Algorithm with matrix inverse mod N

I am implementing an extended Eucilid algorithm with matrix mod N. This is my code implementation:

JavaScript

Now, I need to calculate the matrix inverse mod 36 with the following matrix:

JavaScript

(This is the video link:)

matrix inverse mod N

However, my code can only get x = -11, y = -4, exactly it is a solution of equation 13x = 36y + 1, but in the video the solution is x = 25, y = 9, so how do I change my code to meet this situation?

Advertisement

Answer

−11 is congruent to 25 mod 36, so in Python you can just take x % N.

Advertisement