def square_roots_for_p_5_mod_8(n)
      case power n, (prime - 1) / 4
      when 1
        candidate = power n, (prime + 3) / 8
      when prime - 1
        candidate = mod 2 * n * power(4 * n, (prime - 5) / 8)
      else
        # I think this can happen because we are not checking the Jacobi.
        return []
      end
      square_roots_given_candidate n, candidate
    end
def square_roots_for_p_5_mod_8(n)
      case power n, (prime - 1) / 4
      when 1
        candidate = power n, (prime + 3) / 8
      when prime - 1
        candidate = mod 2 * n * power(4 * n, (prime - 5) / 8)
      else
        # I think this can happen because we are not checking the Jacobi.
        return []
      end
      square_roots_given_candidate n, candidate
    end
This is Algorithm 3.37 from http://cacr.uwaterloo.ca/hac/