def inverse(x, p, errorOnFail=False):
<EOL>assertType(x, BigInt)<EOL>gcd = BigInt()<EOL>inv = BigInt()<EOL>librelic.bn_gcd_ext_lehme(byref(gcd), byref(inv), None, byref(x), byref(p))<EOL>if gcd != <NUM_LIT:1>:<EOL><INDENT>if errorOnFail:<EOL><INDENT>raise Exception("<STR_LIT>".<EOL>format(long(gcd)))<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>return inv<EOL>
Find the inverse of BigInt @x in a field of (prime) order @p.