2

I'm currently trying to simulate a message mapping on elliptic curve, and I am trying to find a point on the curve y**2 = (x**3 + a*x + b) % p, by setting the x variable as hexadecimal converted string.
However, I don't know whether it's the problem with my implementation or a glitch in the program, but the result is completely different from what I am expecting.

// variables
b = 2455155546008943817740293915197451784769108058161191238065
a = -3
x = 1894290318373708250692331360974342813437992324945519136769
p = 6277101735386680763835789423176059013767194773182842284081
//square root of y to its 4th power
y = (x**3 + a*x + b) % p
y = y ** .5
(y ** 4 - 1 ** 3 - a * x - b) % p
//y itself to its 2nd power
y = (x**3 + a*x + b) % p
y = y
(y ** 2 - 1 ** 3 - a * x - b) % p

For the square root of y to its 4th power, the result turns out to be 0.0, whereas the result for y itself to its 2nd power gives the result 4575606179561504294120638508707052089783083374310823885174. Could anyone please explain to me either what is going on or what I'm doing wrong?

Thank you.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
user65311
  • 23
  • 2

2 Answers2

1

In the code, the expression (y=y** .5) assigns the value of y in exponential format which causes 0.0 in evaluating the expression (y ** 4 - 1 ** 3 - a * x - b) % p.

If you want to continue with square root of y to its 4th power, the value of y in exponential format can be converted into int (y=int(y** .5))in this case and then evaluate the expression.

However, It provides the approximate result.

  • Thank you very much for your answer Salai. I am currently trying to find a y coordinate for the Elliptic Curve equation y ** 2 = x ** 3 + ax + b with a given x which is a big number of 192 bits. Do you know how I can get the exact y value for a given x in this case? – user65311 Feb 07 '19 at 00:53
  • We can use the decimal module to get the accurate result. Once we import the decimal module (from decimal import *), we can use Decimal(y**.5) in your code to get the accurate result. – Salai Madhavan Feb 07 '19 at 18:19
1

This line y = y ** .5 converts y from int to float.

If you typecast the result back to int, it works as expected: y = int(y ** .5)

You can see this for yourself:

print(type(y))
y = y ** .5
print(type(y))
singleton
  • 111
  • 6