refactor general crt algorithm into separate function

This commit is contained in:
filifa
2025-08-21 20:17:11 -04:00
parent e1dedd9c33
commit 005eac45c0
2 changed files with 26 additions and 20 deletions

View File

@@ -63,6 +63,23 @@ func CRTSolution(a1, n1, a2, n2 *big.Int) (*big.Int, *big.Int) {
return x, N
}
func CRTSolutionGeneral(remainders, moduli []*big.Int) (*big.Int, *big.Int) {
n1 := new(big.Int)
a1 := new(big.Int)
for i, n2 := range moduli {
a2 := remainders[i]
if i == 0 {
a1.Set(a2)
n1.Set(n2)
continue
}
a1, n1 = CRTSolution(a1, n1, a2, n2)
}
return a1, n1
}
func ArePairwiseCoprime(moduli []*big.Int) bool {
z := new(big.Int)
for i, a := range moduli {