#!/usr/bin/python3
# -*- coding: utf-8 -*-

from DLP.pohlig_hellman import pohlig_hellman
from elliptic_curves.elliptic_curve import Point


def EC_pohlig_hellman(G, A, curve, order=None):
    """Pohlig-Hellman algorithm for computing discrete logarithms
    over an elliptic curve `curve` whose order is a smooth integer.

    INPUT:
    - `G` a point of `curve` of order `order`
    - `A` a point of the group generated by `G`

    OUTPUT:
    - `n` such that `A = n*G`
    """

    if order is None:
        order = G.order()

    G, A = MultiplicativePoint(G), MultiplicativePoint(A)
    return pohlig_hellman(G, A, curve, order)


class MultiplicativePoint(Point):
    def __init__(self, point):
        super().__init__(point.curve(), point.x, point.y, point.z)

    def __mul__(self, other):
        return super().__add__(other)

    def __pow__(self, n):
        return super().__mul__(n)

    def inverse(self):
        return super().__neg__()

    def __truediv__(self, other):
        return super().__sub__(other)

    def __rtruediv__(self, other):
        return super().__rsub__(other)