椭圆曲线加倍并在python中添加实现

时间:2018-10-01 16:35:37

标签: python multiplication elliptic-curve

我正在尝试实现“双重加法”算法,以快速在Python中绘制椭圆曲线上的点(请参阅3)。

基于先前的答案(关于加法和加倍),

Elliptic curve point addition over a finite field in Python

Wikipedia页面,

https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication

和我的教科书(《信息安全》,马克·史坦普(Mark Stamp)),我想到了以下代码:

def point_add(N_x, N_y, Q_x, Q_y, p):
    m = (Q_y - N_y) * pow((Q_x-N_x), p-2, p)
    ret_x = (m ** 2 - N_x - Q_x) % p
    ret_y = (m*(N_x - ret_x) - N_y) % p
    return ret_x, ret_y


def point_double(N_x, N_y, a, p):
    m = (3*(N_x ** 2)+a) * pow(2*N_y, p-2, p)   
    ret_x = (m ** 2 - N_x - Q_x) % p
    ret_y = (m*(N_x - ret_x) - N_y) % p
    return ret_x, ret_y


multiplier_A = 44
multiplier_B = 57
a = 10
b = -21
p = 41
N_x = 3
N_y = 6
Q_x = 0
Q_y = 0

multiplier_A = list(bin(multiplier_A)[2:])
multiplier_B = list(bin(multiplier_B)[2:])

for x_a in multiplier_A:
    if x_a == '1':
        Q_x, Q_y = point_add(N_x, N_y, Q_x, Q_y, p)
    N_x, N_y = point_double(N_x, N_y, a, p)

print(Q_x, Q_y)

足够确定会返回错误的结果。

我哪里出错了?从头开始的新实现也非常受欢迎。

更新

我想将点(3,6)乘以multiplier_Amultiplier_B。目前,我仅尝试multiplier_A(3,6)

abp是椭圆曲线的参数

0 个答案:

没有答案