Can you add a docstring to this and `_egcd` explaining what they do?