Ask Your Question

klx's profile - activity

2023-11-07 21:40:51 +0200 marked best answer Finding the roots of a quartic in GF(p)[x], roots are not correct

I'm trying to implement point halving in Secp256K1 from the article;

https://arxiv.org/pdf/0706.4379.pdf

p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
q =  115792089237316195423570985008687907852837564279074904382605163141518161494337

R = PolynomialRing(GF(p),'x')

# x-coordinate of Q where Q = [2]P
qx =  Integer(84538659774007663836420160802839342215744092791779235474817172502887599548487)

g = (2 *x + qx)*(4*(x^3+7)) - (3*x^2)^2


fr = g.roots()

print(fr)


#One of the roots
t = 82764486716702815285605477501188164702466527314352175978120539775788537185277


gg = ((2 *t + qx)*(4*(t^3+7)) - (3*t^2)^2 ) % p

print( "Test root =", gg)

print("\np = ", p)

All the roots contain sqrt(1/7). below one of them.

   (-sqrt(1/7)*sqrt(84538659774007663836420160802839342215744092791779235474817172502887599548487*49^(2/3) - 7*49^(1/3) - 1208359250574819481534600080392050605105087726810769820677796001845964969340249259244945328508262182991854365774319030049384798743132808313732414554357442504885087643109348338916273438084667558118997277395074665220381651943716674620*49^(2/3)/sqrt(49^(2/3) + 7146784996385421511995375187185600364500640046755442503138794024029777351843969475778650820373992863145285880253980604219684490748086217167422326263989169*49^(1/3) - 591770618418053646854941125619875395510208649542454648323720207520213196839409) + 100054989949395901167935252620598405103008960654576195043943116336416882925815572660901111485235900084034002323555728459075582870473207040343912567695848366) - 1/7*sqrt(49^(2/3)*(49^(2/3) + 7146784996385421511995375187185600364500640046755442503138794024029777351843969475778650820373992863145285880253980604219684490748086217167422326263989169*49^(1/3) - 591770618418053646854941125619875395510208649542454648323720207520213196839409)) + 84538659774007663836420160802839342215744092791779235474817172502887599548487, 1)

Normally, I was expecting one root in mod p and an irreducible of degree 3. The expected root is t and it satisfies the equation.

Is this a simplification problem? Or something else?

2023-11-07 21:33:38 +0200 commented answer Finding the roots of a quartic in GF(p)[x], roots are not correct

Great, thanks.

2023-11-07 21:07:38 +0200 edited question Finding the roots of a quartic in GF(p)[x], roots are not correct

Finding the roots of a quartic in GF(p)[x], roots are not correct I'm trying to implement point halving in Secp256K1 fro

2023-11-07 21:04:38 +0200 asked a question Finding the roots of a quartic in GF(p)[x], roots are not correct

Finding the roots of a quartic in GF(p)[x], roots are not correct I'm trying to implement point halving in Secp255K1 fro

2023-11-05 20:54:42 +0200 received badge  Popular Question (source)
2023-02-21 14:55:33 +0200 received badge  Notable Question (source)
2023-02-12 05:05:35 +0200 received badge  Famous Question (source)
2022-12-29 16:25:16 +0200 received badge  Notable Question (source)
2022-10-15 13:40:55 +0200 received badge  Popular Question (source)
2022-10-06 16:15:40 +0200 received badge  Notable Question (source)
2022-10-06 16:15:40 +0200 received badge  Popular Question (source)
2022-10-04 00:44:39 +0200 commented answer finding 4-torsion point on elliptic curve

https://doc.sagemath.org/html/en/reference/arithmetic_curves/sage/schemes/elliptic_curves/ell_point.html

2022-04-13 02:22:59 +0200 marked best answer ExtGCD in Finite Fields

I want to implement Extended GCD with SageMath so that the internal can be printed. The below is a modification of this. This should be straightforward, however, I might miss something;

def extended_euclides(a,b):

    s = 0; old_s = 1
    t = 1; old_t = 0
    r = b; old_r = a

    while r != 0:
        quotient,rem = old_r.quo_rem(r)

        old_r, r = r, old_r - quotient*r
        old_s, s = s, old_s - quotient*s
        old_t, t = t, old_t - quotient*t
    return [old_r, old_s, old_t]

K.<a> =  GF(2^8, modulus=x^8+x^4+x^3+x+1)
print(K)
print("m = ", K.modulus())

g = a^7 + a^5 + a^4 + a
h = a^4 + a^2 + 1

r,s,t = extended_euclides(g,h)

print("The GCD of \n \t [ {} ] and  \n \t [ {} ]  is \n\t [ {} ]".format(g,h,r))
print("Its Bézout coefficients are {} and {}".format(s,t))
assert r == g.gcd(h), "The gcd should be {}!".format(g.gcd(h))
assert r == s*g + t*h, "The cofactors are wrong!"

In the end, I've got the assertion error AssertionError: The gcd should be 1!

Any idea to solve this?

2022-04-13 02:22:58 +0200 commented answer ExtGCD in Finite Fields

I see. I rather consider calculating it over the finite field instead of polynomials. Since the polynomials are always l

2022-04-12 11:14:57 +0200 edited question ExtGCD in Finite Fields

ExtGCD in Finite Fields I want to implement Extended GCD with SageMath so that the internal can be printed. The below is

2022-04-12 11:02:29 +0200 asked a question ExtGCD in Finite Fields

ExtGCD in Finite Fields I want to implement Extended GCD with SageMath so that the internal can be printed. The below is

2022-02-05 12:52:08 +0200 received badge  Popular Question (source)
2021-12-07 15:47:37 +0200 received badge  Famous Question (source)
2021-11-10 19:16:40 +0200 commented answer Using SageMath Finite Field Extension on Python.

This should be the code. You have forgotten the ** instead of ^ from sage.all import * F = GF(2) R = F['x']; (x,) = R.

2021-11-10 19:04:19 +0200 commented answer Using SageMath Finite Field Extension on Python.

This should be the code. You have forgotten the ** instead of ^ from sage.all import * F = GF(2) R = F['x']; (x,) = R.

2021-11-10 18:41:27 +0200 marked best answer Using SageMath Finite Field Extension on Python.

Yes, I want to the reverse, use the SageMath in Python.

I've seen this on ask.sagemath and stackoverflow

I want to use this in Python

k = GF(2)
R.<x> = k[]
k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')

The python code

from sage.all import *

F = GF(2)
R.<x> = k[]
K = F.extension(x^4 + x + 1, 'a')

print(K)

the R.<x> = k[] fails...

Is there a way to do this in python?

My final aim is finding the multiplicative inverse of an element using python with the sagemath import.

2021-11-10 18:41:21 +0200 commented answer Using SageMath Finite Field Extension on Python.

This should be the code. You have forgotten the ** instead of ^ from sage.all import * F = GF(2) R = F['x']; (x,) = R.

2021-11-10 17:44:41 +0200 edited question Using SageMath Finite Field Extension on Python.

Using SageMath Finite Field Extension on Python. Yes, I want to the reverse, use the SageMath in Python. I've seen this

2021-11-10 17:43:18 +0200 asked a question Using SageMath Finite Field Extension on Python.

Using SageMath Finite Field Extension on Python. Yes, I want to the reverse, use the SageMath in Python. I've seen this

2021-11-03 19:05:08 +0200 commented answer Change of variables in symbolic computation

Also, I've seen this answer of yours and the function is not working, at least for me. Something has changed with Python

2021-11-03 19:04:41 +0200 commented answer Change of variables in symbolic computation

Also, I've seen this answer of yours and the function is not working, at least for me.

2021-11-03 19:04:16 +0200 commented answer Change of variables in symbolic computation

Also, I've seen this answer of yours and the function is not working, at least for me.

2021-11-03 18:59:39 +0200 commented answer Change of variables in symbolic computation

I guess substitute_expression is for something else, however, I couldn't find it in the docs.

2021-11-03 09:39:49 +0200 marked best answer Change of variables in symbolic computation

I need to change Y into 1/2 *( y - a1 * x - a3) so that I can change variables in Elliptic curves.

var("X,Y,Z,x,y,a1,a2,a3,a4,a5,a6")
F = Y^2  *Z + a1 * X*Y *Z + a3 *Y *Z^2 - X^3 - a2 *X^2 * Z + a4*X*Z^ 2 + a6*Z^3
print(F)
F.substitute_expression(Y == 1/2 *( y - a1 * x - a3))  
print(F)

This produces an error on the 4th line;

AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'substitute_expression'

What is the proper way to change the variables?

2021-11-02 19:11:58 +0200 asked a question Change of variables in symbolic computation

Change of variables in symbolic computation I need to change Y into 1/2 *( y - a1 * x - a3) so that I can change variabl

2021-02-16 14:53:44 +0200 answered a question evaluating inverse erf
def probit(p):
    return (sqrt(2)*erfinv(2*p-1)).n()

print(probit(0.025)) #Wikipedia Verification
print(probit(0.975))

P1 = [] 
for n in xsrange(1,100):
    P1.append( ( n , probit(n/100.0)) )

G1 = point2d(P1,color='blue',pointsize=10)
G1.show()
2021-02-16 13:50:52 +0200 commented answer evaluating inverse erf
2021-02-16 13:47:44 +0200 asked a question probit, erfinv, and inconsistency with Wikipedia

I've used the erfinv

def probit(p):
    return e^(sqrt(2)*erfinv(2*p-1)).n()

print(probit(0.025))
print(probit(0.975))

and outputs

0.140863494093217
7.09907138423134

Wikipedia states that

$\operatorname{probit}(0.025) = -1.96 = -\operatorname{probit}(0.975)$

Interestingly

print(e^(sqrt(2)*erfinv(1/2)).n())

outputs

1.96303108415826

Am I missing a point here?

2021-02-06 13:18:41 +0200 received badge  Enthusiast
2021-01-19 20:28:01 +0200 commented answer Solving symbolic equations to IntegerModRing(26)

[k_1 + 11x2, k_2 + 11x2, k_3, k_4 + 1, x1 + 23*x2, 2]. I've got this as an experiment, what is the value of k_3 and the last 2?

2021-01-19 20:24:05 +0200 commented answer Solving symbolic equations to IntegerModRing(26)

No automatic way form basis to eq.sub?

2021-01-19 20:10:04 +0200 received badge  Commentator