lib/ed25519_keccak/ed25519base.rb
def recover_x(y, sign)
      return nil if y >= @@p
      # x2 means x^2
      x2 = (y*y-1) * modp_inv(@@d*y*y+1)
      # when x2==0 and sign!=0, these combination of arguments is illegal
      if x2.equal? 0 then
        unless sign.equal? 0 then
          return nil
        else
          return 0
        end
      end
      # Compute square root of x2
      x = pow_mod(x2 , ((@@p+3) / 8) , @@p)
      x = x * @@modp_sqrt_m1 % @@p unless ((x*x - x2) % @@p).equal? 0
      return nil unless ((x*x - x2) % @@p).equal? 0
      x = @@p - x  unless (x & 1).equal? sign
      return x
    end
def recover_x(y, sign)
      return nil if y >= @@p
      # x2 means x^2
      x2 = (y*y-1) * modp_inv(@@d*y*y+1)
      # when x2==0 and sign!=0, these combination of arguments is illegal
      if x2.equal? 0 then
        unless sign.equal? 0 then
          return nil
        else
          return 0
        end
      end
      # Compute square root of x2
      x = pow_mod(x2 , ((@@p+3) / 8) , @@p)
      x = x * @@modp_sqrt_m1 % @@p unless ((x*x - x2) % @@p).equal? 0
      return nil unless ((x*x - x2) % @@p).equal? 0
      x = @@p - x  unless (x & 1).equal? sign
      return x
    end
region point manipulation 
 Compute corresponding x-coordinate, with low bit corresponding to
 sign, or return nil on failure