import random
from sage.misc.misc import cputime

# Jubjub curve
from curve import Curve, Point
p_jubjub = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
a_jubjub = -1
d_jubjub = 0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1
r_jubjub = 0x0e7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7
J = Curve(p_jubjub, a_jubjub, d_jubjub, r_jubjub, 8)
Q = J.point_of_order_r()
m = random.randint(0,r_jubjub)
# fixed Q and m
Q = Point(8265506417937309428145637863657901096326803541555843920545271411571019173188,43078099614076354221581797221645845941231628185943136834944943003176856371463,2895621973748525387977156146651243021079099683508751012131548696447119063105,J)
m = 2363201799752215928069851892839815906013532842010879554933277259503426635572

t = cputime()
for i in range(1000):
    R1 = Q.scalar_mul(m)
t = cputime(t)
print("Jubjub:\t\t\t{:5.3f}ms".format(t))

# Bandersnatch curve
from bandersnatch import Bandersnatch, BandersnatchPoint

#
# code from the params-TE.py file
# this code can be recomputed using `sage get_params.py`
#
import sage.all
from sage.rings.finite_rings.finite_field_constructor import FiniteField
# Twisted Edwards parameters
p=52435875175126190479447740508185965837690552500527637822603658699938581184513
Fp=FiniteField(p)
# curve equation coefficients
a=Fp(52435875175126190479447740508185965837690552500527637822603658699938581184508)
d_num=Fp(138827208126141220649022263972958607803)
d_den=Fp(171449701953573178309673572579671231137)
d=Fp(45022363124591815672509500913686876175488063829319466900776701791074614335719)
# endomorphism coefficients
b=Fp(37446463827641770816307242315180085052603635617490163568005256780843403514036)
c=Fp(49199877423542878313146170939139662862850515542392585932876811575731455068989)
# endomorphism eigenvalue L on the subgroup of size r
r=13108968793781547619861935127046491459309155893440570251786403306729687672801
cofactor = 4
curve_order=r*cofactor
L=8913659658109529928382530854484400854125314752504019737736543920008458395397
xG_TE=Fp(0x29c132cc2c0b34c5743711777bbe42f32b79c022ad998465e1e71866a252ae18)
yG_TE=Fp(0x2a6c669eda123e0f157d8b50badcd586358cad81eee464605e3167b6cc974166)
zG_TE=Fp(0x1)
#
#
#

C = Bandersnatch(p, a, d,
                 L, r, cofactor,
                 b,c)
P = C.point_of_order_r()
n = random.randint(0,r)
# fixed P and n
P = BandersnatchPoint(13738737789055671334382939318077718462576533426798874551591468520593954805549,11575885077368931610486103676191793534029821920164915325066801506752632626968,14458123306641001284399433086015669988340559992755622870694102351476334505845,C)
n = 4257185345094557079734489188109952172285839137338142340240392707284963971010

t2 = cputime()
for i in range(1000):
    R2 = P.fast_scalar_mul(n)
t2 = cputime(t2)
print('Bandersnatch:\t\t{:5.3f}ms ({:2.0f}% faster)'.format(t2, 100*(t-t2)/t2))

import random
from sage.misc.misc import cputime

# Jubjub curve
from curve import Curve, Point
p_jubjub = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
a_jubjub = -1
d_jubjub = 0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1
r_jubjub = 0x0e7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7
J = Curve(p_jubjub, a_jubjub, d_jubjub, r_jubjub, 8)
Q = J.point_of_order_r()
m = random.randint(0,r_jubjub)
# fixed Q and m
Q = Point(8265506417937309428145637863657901096326803541555843920545271411571019173188,43078099614076354221581797221645845941231628185943136834944943003176856371463,2895621973748525387977156146651243021079099683508751012131548696447119063105,J)
m = 2363201799752215928069851892839815906013532842010879554933277259503426635572

t = cputime()
for i in range(1000):
    R1 = Q.scalar_mul(m)
t = cputime(t)
print("Jubjub:\t\t\t{:5.3f}ms".format(t))

# Bandersnatch curve
from bandersnatch import Bandersnatch, BandersnatchPoint

#
# code from the params-TE.py file
# this code can be recomputed using `sage get_params.py`
#
import sage.all
from sage.rings.finite_rings.finite_field_constructor import FiniteField
# Twisted Edwards parameters
p=52435875175126190479447740508185965837690552500527637822603658699938581184513
Fp=FiniteField(p)
# curve equation coefficients
a=Fp(52435875175126190479447740508185965837690552500527637822603658699938581184508)
d_num=Fp(138827208126141220649022263972958607803)
d_den=Fp(171449701953573178309673572579671231137)
d=Fp(45022363124591815672509500913686876175488063829319466900776701791074614335719)
# endomorphism coefficients
b=Fp(37446463827641770816307242315180085052603635617490163568005256780843403514036)
c=Fp(49199877423542878313146170939139662862850515542392585932876811575731455068989)
# endomorphism eigenvalue L on the subgroup of size r
r=13108968793781547619861935127046491459309155893440570251786403306729687672801
cofactor = 4
curve_order=r*cofactor
L=8913659658109529928382530854484400854125314752504019737736543920008458395397
xG_TE=Fp(0x29c132cc2c0b34c5743711777bbe42f32b79c022ad998465e1e71866a252ae18)
yG_TE=Fp(0x2a6c669eda123e0f157d8b50badcd586358cad81eee464605e3167b6cc974166)
zG_TE=Fp(0x1)
#
#
#

C = Bandersnatch(p, a, d,
                 L, r, cofactor,
                 b,c)
P = C.point_of_order_r()
n = random.randint(0,r)
# fixed P and n
P = BandersnatchPoint(13738737789055671334382939318077718462576533426798874551591468520593954805549,11575885077368931610486103676191793534029821920164915325066801506752632626968,14458123306641001284399433086015669988340559992755622870694102351476334505845,C)
n = 4257185345094557079734489188109952172285839137338142340240392707284963971010

t2 = cputime()
for i in range(1000):
    R2 = P.fast_scalar_mul(n)
t2 = cputime(t2)
print('Bandersnatch:\t\t{:5.3f}ms ({:2.0f}% faster)'.format(t2, 100*(t-t2)/t2))

# Jubjub curve # fixed Q and m # Bandersnatch curve # # code from the params-TE.py file # this code can be recomputed using `sage get_params.py` # # Twisted Edwards parameters # curve equation coefficients # endomorphism coefficients # endomorphism eigenvalue L on the subgroup of size r # # # # fixed P and n