// For each input modulus 'x' and remainderTree parent 'y', compute z = (y%(x*x))/x; gcd(z, x) func lowmemRemainderTreeFinal(input, moduli chan *gmp.Int, output chan<- Collision) { defer close(output) tmp := new(gmp.Int) for y := range input { for i := 0; i < 2; i++ { modulus, ok := <-moduli if !ok { log.Print("Odd number of moduli? (should only see this once)") continue } tmp.Mul(modulus, modulus) tmp.Rem(y, tmp) tmp.Quo(tmp, modulus) if tmp.GCD(nil, nil, tmp, modulus).BitLen() != 1 { q := new(gmp.Int).Quo(modulus, tmp) output <- Collision{ Modulus: modulus, P: tmp, Q: q, } tmp = new(gmp.Int) } } y.Clear() } }
// For each input modulus 'x' and remainderTree parent 'y', compute z = (y%(x*x))/x; gcd(z, x) func remainderTreeFinal(lastLevel, moduli []*gmp.Int, output chan<- Collision, wg *sync.WaitGroup, start, step int) { tmp := new(gmp.Int) for i := start; i < len(moduli); i += step { modulus := moduli[i] y := lastLevel[i/2] tmp.Mul(modulus, modulus) tmp.Rem(y, tmp) tmp.Quo(tmp, modulus) if tmp.GCD(nil, nil, tmp, modulus).BitLen() != 1 { q := new(gmp.Int).Quo(modulus, tmp) output <- Collision{ Modulus: modulus, P: tmp, Q: q, } tmp = new(gmp.Int) } } wg.Done() }