public BigInteger get_inverse(BigInteger a, BigInteger b) { Euclid_result result = euclid(a, b); BigInteger c = result.y; if (c < 0) { c = c + a; } return(c); }
public Euclid_result euclid(BigInteger a, BigInteger b) { BigInteger A; BigInteger B; BigInteger x1 = 0; BigInteger y1 = 1; BigInteger x = 0; BigInteger y = 0; BigInteger AdivB; BigInteger AmodB; List<BigInteger> Div = new List<BigInteger>(); if (a < b) { A = b; B = a; } else { A = a; B = b; } while (true) { AdivB = A / B; AmodB = A % B; Div.Insert(0, AdivB); if (AmodB == 0) break; A = B; B = AmodB; } for (int i = 1; i < Div.Count; i++) { x = y1; y = x1 - y1 * Div[i]; x1 = x; y1 = y; } if (a < b) { A = b; B = a; } else { A = a; B = b; } Euclid_result result = new Euclid_result() { C = A * x + B * y, x = x, y = y }; Div.Clear(); return result; }
public Euclid_result euclid(BigInteger a, BigInteger b) { BigInteger A; BigInteger B; BigInteger x1 = 0; BigInteger y1 = 1; BigInteger x = 0; BigInteger y = 0; BigInteger AdivB; BigInteger AmodB; List <BigInteger> Div = new List <BigInteger>(); if (a < b) { A = b; B = a; } else { A = a; B = b; } while (true) { AdivB = A / B; AmodB = A % B; Div.Insert(0, AdivB); if (AmodB == 0) { break; } A = B; B = AmodB; } for (int i = 1; i < Div.Count; i++) { x = y1; y = x1 - y1 * Div[i]; x1 = x; y1 = y; } if (a < b) { A = b; B = a; } else { A = a; B = b; } Euclid_result result = new Euclid_result() { C = A * x + B * y, x = x, y = y }; Div.Clear(); return(result); }