The logic here is a bit twisted. The old code has its fuckery:

`if (y.mod(new BigInteger('2')).toString() != ''+(type % 2)) { y = p.subtract(y) }`

 but its logic is fairly straightforward to translate:

`(isYEven ^ beta.isEven) ? p.substract(beta) : beta `

@dcousens thoughts?