def test_RDR():
    p = 6277101735386680763835789423207666416083908700390324961279
    r = 6277101735386680763835789423176059013767194773182842284081
    # s = 0x3045ae6fc8422f64ed579528d38120eae12196d5L
    c = 0x3099d2bbbfcb2538542dcd5fb078b6ef5f3d6fe2c745de65
    b = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1
    Gx = 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012
    Gy = 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811

    c192 = CurveFp(p, -3, b)
    p192 = Point(c192, Gx, Gy, r)
    D = [1, 3, 23, 27]
    k = 31415
    RDR = [1, 0, 0, 0, 0, 0, -1, 0, 0, 0, -27, 0, 0, 0, 0, 23]
    N = k * p192
    Q = p192.RDR_multiply(D, RDR)
    print(
        "Nx > ",
        N.x(),
    )
    print(", Ny > ", N.y())
    print(
        "Qx >",
        Q.x(),
    )
    print(", Qy > ", Q.y())
Esempio n. 2
0
from ellipticcurve import CurveFp, Point

# Certicom secp256-k1
_a = 0x0000000000000000000000000000000000000000000000000000000000000000
_b = 0x0000000000000000000000000000000000000000000000000000000000000007
_p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
_Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
_Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
_r = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141

generator_secp256k1 = Point(CurveFp(_p, _a, _b), _Gx, _Gy, _r)
def test_ellipticcurve():
    class FailedTest(Exception):
        pass

    def test_add(c, x1, y1, x2, y2, x3, y3):
        """We expect that on curve c, (x1,y1) + (x2, y2 ) = (x3, y3)."""
        p1 = Point(c, x1, y1)
        p2 = Point(c, x2, y2)
        p3 = p1 + p2
        print_("%s + %s = %s" % (p1, p2, p3), end=' ')
        if p3.x() != x3 or p3.y() != y3:
            raise FailedTest("Failure: should give (%d,%d)." % (x3, y3))
        else:
            print_(" Good.")

    def test_double(c, x1, y1, x3, y3):
        """We expect that on curve c, 2*(x1,y1) = (x3, y3)."""
        p1 = Point(c, x1, y1)
        p3 = p1.double()
        print_("%s doubled = %s" % (p1, p3), end=' ')
        if p3.x() != x3 or p3.y() != y3:
            raise FailedTest("Failure: should give (%d,%d)." % (x3, y3))
        else:
            print_(" Good.")

    def test_double_infinity(c):
        """We expect that on curve c, 2*INFINITY = INFINITY."""
        p1 = INFINITY
        p3 = p1.double()
        print_("%s doubled = %s" % (p1, p3), end=' ')
        if p3.x() != INFINITY.x() or p3.y() != INFINITY.y():
            raise FailedTest("Failure: should give (%d,%d)." %
                             (INFINITY.x(), INFINITY.y()))
        else:
            print_(" Good.")

    def test_multiply(c, x1, y1, m, x3, y3):
        """We expect that on curve c, m*(x1,y1) = (x3,y3)."""
        p1 = Point(c, x1, y1)
        p3 = p1 * m
        print_("%s * %d = %s" % (p1, m, p3), end=' ')
        if p3.x() != x3 or p3.y() != y3:
            raise FailedTest("Failure: should give (%d,%d)." % (x3, y3))
        else:
            print_(" Good.")

    # A few tests from X9.62 B.3:

    c = CurveFp(23, 1, 1)
    test_add(c, 3, 10, 9, 7, 17, 20)
    test_double(c, 3, 10, 7, 12)
    test_add(c, 3, 10, 3, 10, 7, 12)  # (Should just invoke double.)
    test_multiply(c, 3, 10, 2, 7, 12)

    test_double_infinity(c)

    # From X9.62 I.1 (p. 96):

    g = Point(c, 13, 7, 7)

    check = INFINITY
    for i in range(7 + 1):
        p = (i % 7) * g
        print_("%s * %d = %s, expected %s . . ." % (g, i, p, check), end=' ')
        if p == check:
            print_(" Good.")
        else:
            raise FailedTest("Bad.")
        check = check + g

    # NIST Curve P-192:
    p = 6277101735386680763835789423207666416083908700390324961279
    r = 6277101735386680763835789423176059013767194773182842284081
    # s = 0x3045ae6fc8422f64ed579528d38120eae12196d5L
    c = 0x3099d2bbbfcb2538542dcd5fb078b6ef5f3d6fe2c745de65
    b = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1
    Gx = 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012
    Gy = 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811

    c192 = CurveFp(p, -3, b)
    p192 = Point(c192, Gx, Gy, r)

    # Checking againtest_doublest some sample computations presented
    # in X9.62:
    digt_set = [
        1, 23, 27, 43, 47, 49, 53, 57, 69, 95, 103, 113, 117, 129, 153, 155,
        171, 173, 175, 187, 191, 199, 213, 215, 239, 247, 271, 275, 281, 297,
        303, 315, 321, 327, 339, 349, 369, 383, 391
    ]
    RDR = [
        53, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0, 0, 0, 0,
        0, 0, -95, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 0, 0, 0, -175, 0, 0, 0,
        0, 349, 0, 0, 0, 0, 0, 69, 0, 0, 0, 0, 0, 187, 0, 0, 0, 0, 0, 0, 0, 0,
        47, 0, 0, 0, 0, -349, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 27, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, -213, 0, 0, 0, 0, 0, 0, 0, 327, 0, 0, 0, 0, 0, 0,
        -349, 0, 0, 0, 0, 0, 0, 0, 0, 187, 0, 0, 0, 0, 0, 0, 0, 0, -57, 0, 0,
        0, 0, 0, 0, 297, 0, 0, 0, 0, 0, 0, 339, 0, 0, 0, 0, 0, 0, 0, -391, 0,
        0, 0, 0, 0, 0, -391, 0, 0, 0, 0, 0, 0, -391, 0, 0, 0, 0, 0, -247, 0, 0,
        0, 0, 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, 187
    ]
    naf = [
        1, 0, -1, 0, 1, 0, 1, 0, 0, 1, 0, 0, -1, 0, -1, 0, -1, 0, -1, 0, 1, 0,
        -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, -1, 0, -1, 0, 0, -1,
        0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 1,
        0, 0, 1, 0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 1, 0, -1, 0, 0, -1, 0, -1,
        0, 0, -1, 0, 1, 0, -1, 0, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
        1, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 1, 0, 1, 0, -1,
        0, -1, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0,
        0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,
        -1, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, -1
    ]
    d = 651056770906015076056810763456358567190100156695615665659
    startTime = time.time()
    Q = d * p192
    endTime = time.time()
    print("Double and add > ", endTime - startTime)

    startTime = time.time()
    G = p192.RDR_multiply(digt_set, RDR)
    endTime = time.time()
    print("RDR > ", endTime - startTime)

    startTime = time.time()
    N = p192.NAF_multiply(naf)
    endTime = time.time()
    print("NAF > ", endTime - startTime)

    print("N > ", N.y())
    print("X > ", G.y())
    print("Q > ", Q.y())
    if Q.x() != 0x62B12D60690CDCF330BABAB6E69763B471F994DD702D16A5:
        raise FailedTest("p192 * d came out wrong.")
    else:
        print_("p192 * d came out right.")

    k = 6140507067065001063065065565667405560006161556565665656654
    R = k * p192
    if R.x() != 0x885052380FF147B734C330C43D39B2C4A89F29B0F749FEAD \
       or R.y() != 0x9CF9FA1CBEFEFB917747A3BB29C072B9289C2547884FD835:
        raise FailedTest("k * p192 came out wrong.")
    else:
        print_("k * p192 came out right.")

    u1 = 2563697409189434185194736134579731015366492496392189760599
    u2 = 6266643813348617967186477710235785849136406323338782220568
    temp = u1 * p192 + u2 * Q
    if temp.x() != 0x885052380FF147B734C330C43D39B2C4A89F29B0F749FEAD \
       or temp.y() != 0x9CF9FA1CBEFEFB917747A3BB29C072B9289C2547884FD835:
        raise FailedTest("u1 * p192 + u2 * Q came out wrong.")
    else:
        print_("u1 * p192 + u2 * Q came out right.")
def curve521():
    # NIST Curve P-521
    p = 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151
    r = 6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449
    # SEED = 0xd09e8800291cb85396cc6717393284aaa0da64ba
    # c = 0x0b48bfa5f420a34949539d2bdfc264eeeeb077688e44fbf0ad8f6d0edb37bd6b533281000518e19f1b9ffbe0fe9ed8a3c2200b8f875e523868c70c1e5bf55bad637
    b = 0x051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00
    Gx = 0xc6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66
    Gy = 0x11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650

    c521 = CurveFp(p, -3, b)
    p521 = Point(c521, Gx, Gy, r)

    d = 2695995667150639794667015087019625940457807714424391721682712368058238947189273490172349807129834790127349087129834623486127461012630462184628923461201280461
    # Checking againtest_doublest some sample computations presented
    # in X9.62:
    digit_set = [
        1, 7, 23, 25, 33, 37, 39, 43, 49, 53, 63, 65, 67, 71, 75, 77, 85, 89,
        97, 99, 103, 107, 113, 115, 117, 119, 127, 131, 133, 135, 145, 151,
        153, 157, 163, 165, 171, 181, 183, 185, 189, 191, 197, 199, 201, 203,
        207, 211, 213, 219, 221, 225, 227, 229, 233, 235, 237, 243, 247, 255,
        257, 259, 269, 283, 287, 295, 307, 311, 321, 329, 333, 335, 339, 341,
        345, 349, 351, 371, 373, 381, 385, 393, 403, 405, 411, 419, 421, 429,
        431, 433, 435, 437, 441, 459, 471, 489, 503, 519, 521, 523, 527, 529,
        535, 537, 543, 547, 549, 563, 567, 577, 585, 589, 601, 603, 609, 615,
        619, 627, 633, 635, 641, 643, 655, 659, 665, 671, 675, 681, 687, 709,
        711, 719, 727, 729, 731, 733, 735, 737, 741, 743, 745, 747, 749, 751,
        755, 761, 763, 765, 771, 777, 779, 783, 785, 789, 797, 803, 807, 813,
        817, 827, 839, 841, 845, 853, 859, 863, 865, 871, 873, 875, 883, 887,
        889, 891, 895, 897, 899, 901, 905, 909, 915, 925, 927, 933, 935, 945,
        949, 961, 963, 967, 977, 983, 985, 987, 989, 995
    ]
    # IFRA = [201, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 627, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 741, 0, 0, 0, 0, 0, 0, 0, 0, 0, -709, 0, 0, 0, 0, 0, 0, 0, -411, 0, 0, 0, 0, 0, 0, 0, 0, 0, -189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -803, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 765, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -985, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -747, 0, 0, 0, 0, 0, 0, 0, 0, 203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 433, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, -963, 0, 0, 0, 0, 0, 0, 0, 0, -735, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 887, 0, 0, 0, 0, 0, 0, 0, 0, 0, 751, 0, 0, 0, 0, 0, 0, 0, 0, -963, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -741, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 807, 0, 0, 0, 0, 0, 0, 0, 0, 727, 0, 0, 0, 0, 0, 0, 0, 0, 0, 103, 0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0,0, 0, 0, 0, -345, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -995, 0, 0, 0, 0, 0, 0, 0, 0, -419, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 887, 0, 0, 0, 0, 0, 0, 0, 873, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -181, 0, 0, 0, 0, 0, 0, 0, 0, 0, -609, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 527, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -183, 0, 0, 0, 0, 0, 0, 0, 0, 345, 0, 0, 0, 0, 0, 0, 0, 0, 961, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 711, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 905, 0, 0, 0, 0, 0, 0, 0, 0, 307, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -287, 0, 0, 0, 0, 0, 0, 0, 0, 181, 0, 0, 0, 0, 0, 0, 0, 0, -655, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -351, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-63, 0, 0, 0, 0, 0, 0, 0, 0, 419, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -333, 0, 0, 0, 0, 0, 0, 0, 0, 0, -577, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -563]
    IFRA = [
        201, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 627, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 741, 0, 0, 0, 0, 0, 0, 0,
        0, 0, -709, 0, 0, 0, 0, 0, 0, 0, -411, 0, 0, 0, 0, 0, 0, 0, 0, 0, -189,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -803, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 765, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -985, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -747, 0, 0, 0, 0, 0, 0, 0, 0, 203, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 433, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0,
        0, -963, 0, 0, 0, 0, 0, 0, 0, 0, -735, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        887, 0, 0, 0, 0, 0, 0, 0, 0, 0, 751, 0, 0, 0, 0, 0, 0, 0, 0, -963, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -741, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 807, 0, 0, 0, 0, 0, 0, 0, 0, 727, 0, 0, 0, 0, 0, 0, 0, 0, 0, 103,
        0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0, 0, -345, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -995, 0, 0, 0, 0, 0, 0, 0, 0, -419, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 887, 0, 0, 0, 0, 0, 0, 0, 873, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, -181, 0, 0, 0, 0, 0, 0, 0, 0, 0, -609, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        25, 0, 0, 0, 0, 0, 0, 0, 0, 527, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -183, 0, 0, 0, 0, 0, 0, 0, 0, 345, 0, 0, 0, 0, 0, 0, 0, 0, 961, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 711, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        905, 0, 0, 0, 0, 0, 0, 0, 0, 307, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -287, 0, 0, 0, 0, 0, 0, 0, 0, 181, 0, 0, 0,
        0, 0, 0, 0, 0, -655, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -351, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 419, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, -333, 0, 0, 0, 0, 0, 0, 0, 0, 0, -577, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -563
    ]
    RDR = [
        1, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -945, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -635, 0, 0, 0, 0, 0, 0, 0, 0, 0, 107, 0, 0, 0, 0, 0, 0,
        0, 145, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -845, 0, 0, 0, 0, 0,
        -37, 0, 0, 0, 0, 0, 0, -117, 0, 0, 0, 0, 0, 0, 0, -145, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -771, 0, 0, 0, 0, 0, 0, -33, 0, 0, 0, 0, 0, 0, 0, 145,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -403, 0, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, -421, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 783, 0, 0, 0,
        0, 0, 0, 0, 237, 0, 0, 0, 0, 0, 0, 0, 0, 0, -71, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, -33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -151, 0, 0, 0, 0, 0, 0, 0, 0, 0, -49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        567, 0, 0, 0, 0, 0, 0, 0, 0, -411, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 0, 0,
        0, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 0, 0, 0, -519, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -89, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, -901, 0, 0, 0, 0, 0, 0, 0, 0, -345, 0, 0, 0, 0, 0, 0,
        0, 0, 0, -527, 0, 0, 0, 0, 0, 0, 0, -151, 0, 0, 0, 0, 0, 0, -113, 0, 0,
        0, 0, 0, 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 429, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 899, 0, 0, 0, 0, 0, 0, 0, 0, -157, 0, 0, 0, 0, 0,
        0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 307, 0, 0, 0, 0, 0, 0, 0,
        0, 113, 0, 0, 0, 0, 0, 0, 0, 151, 0, 0, 0, 0, 0, 0, 0, 113, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, -665, 0, 0, 0, 0, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -351, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0,
        0, 0, 0, 0, 419, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -333, 0, 0, 0, 0, 0, 0,
        0, 0, 0, -577, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -563
    ]
    naf = [
        1, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, -1, 0, 1, 0, -1, 0,
        0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, 0,
        1, 0, 1, 0, 0, -1, 0, 1, 0, -1, 0, -1, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0,
        0, 0, 0, 1, 0, 1, 0, 1, 0, 0, -1, 0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 0, 0,
        -1, 0, 1, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0,
        -1, 0, -1, 0, 1, 0, 0, 1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 1, 0, -1, 0,
        0, -1, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0,
        1, 0, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, -1, 0, 0,
        0, -1, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, 1, 0, 0, 1, 0, 0, 0, -1,
        0, 1, 0, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, -1, 0, -1, 0, 0, 1, 0, -1, 0,
        0, 1, 0, 1, 0, 0, 0, 1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 1, 0, -1, 0,
        1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, -1, 0, 1, 0,
        0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, -1,
        0, 0, 0, -1, 0, 1, 0, 1, 0, -1, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 1, 0, 0,
        1, 0, 1, 0, 1, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 1,
        0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 1, 0, 1, 0,
        0, -1, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 1, 0, -1, 0, -1,
        0, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0,
        -1, 0, 1, 0, -1, 0, 1, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, -1, 0, 0, 0,
        -1, 0, 0, -1, 0, 0, 0, 1, 0, -1, 0, -1, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0,
        -1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
        -1, 0, 0, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, 1, 0, -1, 0, 0, -1, 0, -1, 0,
        -1, 0, 0, 1, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0,
        -1, 0, 1, 0, -1, 0, 1
    ]
    wnaf = l_naf.find_naf(
        d, 2,
        get_Wn(digit_set) + 2
    )  #[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -439, 0, 0, 0, 0, 0, 0, 0, 0, 0, -397, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, -163, 0, 0, 0, 0, 0, 0, 0, 0, 0, -473, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 357, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -379, 0, 0, 0, 0, 0, 0, 0, 0, 0, 221, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 505, 0, 0, 0, 0, 0, 0, 0, 0, 0, 505, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -373, 0, 0, 0, 0, 0, 0, 0, 0, 0, -309, 0, 0, 0, 0, 0, 0, 0, 0, 0, 433, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -305, 0, 0, 0, 0, 0, 0, 0, 0, 0, -111, 0, 0, 0, 0, 0, 0, 0, 0, 0, -401, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -137, 0, 0, 0, 0, 0, 0, 0, 0, 0, -451, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 397, 0, 0, 0, 0, 0, 0, 0, 0, 0, -377, 0, 0, 0, 0, 0, 0, 0, 0, 0, -285, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 505, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -89, 0, 0, 0, 0, 0, 0, 0, 0, 0, -451, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -499, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 479, 0, 0, 0, 0, 0, 0, 0, 0, 0, 295, 0, 0, 0, 0, 0, 0, 0, 0, 0, -297, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 345, 0, 0, 0, 0, 0, 0, 0, 0, 0, -121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, -199, 0, 0, 0, 0, 0, 0, 0, 0, 0, -209, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -245, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -393, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 245, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0, -217, 0, 0, 0, 0, 0, 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 461]
    naf_set = []
    naf_set.append(1)
    i = 3
    while (i <= (2**(get_Wn(digit_set) + 1))):
        naf_set.append(i)
        i = i + 2
    i = 100

    doubleadd_time = 0
    naf_time = 0
    rdr_time = 0
    wnaf_time = 0
    ifra_time = 0
    while (i > 0):
        # print i
        startTime = time.time()
        Q = d * p521
        endTime = time.time()
        doubleadd_time = doubleadd_time + (endTime - startTime)
        # print("Double and add > ", endTime - startTime)

        startTime = time.time()
        G = p521.RDR_multiply_index(digit_set, RDR, i)
        endTime = time.time()
        rdr_time = rdr_time + (endTime - startTime)
        # print("RDR > ", endTime - startTime)

        startTime = time.time()
        X = p521.IFRDR_multiply_index(digit_set, IFRA, i)
        endTime = time.time()
        ifra_time = ifra_time + (endTime - startTime)

        startTime = time.time()
        N = p521.NAF_multiply(naf)
        endTime = time.time()
        naf_time = naf_time + (endTime - startTime)
        # print("NAF > ", endTime - startTime)

        startTime = time.time()
        W = p521.wnaf_multiply_index(naf_set, wnaf, i)
        endTime = time.time()
        wnaf_time = wnaf_time + (endTime - startTime)

        i = i - 1

    print("Double and Add average > ", doubleadd_time / 100)
    print("RDR average > ", rdr_time / 100)
    print("IFRA average > ", ifra_time / 100)
    print("NAF average > ", naf_time / 100)
    print("wNAF average > ", wnaf_time / 100)

    print("N > ", N.y())
    print("G > ", G.y())
    print("X > ", X.y())
    print("Q > ", Q.y())
    print("W > ", W.y())
def curve384():
    # NIST Curve P-384
    p = 39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319
    r = 39402006196394479212279040100143613805079739270465446667946905279627659399113263569398956308152294913554433653942643
    # SEED = 0xa335926aa319a27a1d00896a6773a4827acdac73
    # c = 0x79d1e655f868f02fff48dcdee14151ddb80643c1406d0ca10dfe6fc52009540a495e8042ea5f744f6e184667cc722483
    b = 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef
    Gx = 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7
    Gy = 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f

    c384 = CurveFp(p, -3, b)
    p384 = Point(c384, Gx, Gy, r)

    d = 26959956671506397946670150870196259404578077144243917216827126959956671506397946670150870196259404578077144243917216
    # Checking againtest_doublest some sample computations presented
    # in X9.62:
    digit_set = [
        1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
        39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73,
        75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107,
        109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135,
        137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163,
        165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191,
        193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219,
        221, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247,
        249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275,
        277, 279, 281, 283, 285, 287, 289, 291, 293, 295, 297, 299, 301, 303,
        305, 307, 309, 311, 313, 315, 317, 319, 321, 323, 325, 327, 329, 331,
        333, 335, 337, 339, 341, 343, 345, 347, 349, 351, 353, 355, 357, 359,
        361, 363, 365, 367, 369, 371, 373, 375, 377, 379, 381, 383, 385, 387,
        389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, 411, 413, 415,
        417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443,
        445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 469, 471,
        473, 475, 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, 499,
        501, 503, 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, 525, 527,
        529, 531, 533, 535, 537, 539, 541, 543, 545, 547, 549, 551
    ]
    # IFRA = [175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 333, 0, 0, 0, 0, 0, 0, 0, 0, 0, -471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -221, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, -535, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -61, 0, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0, 0, 0, 0, 0, 0, 0, 0, 0, -171, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -321, 0, 0, 0, 0, 0, 0, 0, 0, 0, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, -145, 0, 0, 0, 0, 0, 0, 0, 0, 0, -433, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -209, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 0, 0, 0, 0,0, 0, 0, 0, 0, -173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -251, 0, 0, 0, 0, 0, 0, 0, 0, 0, -299, 0, 0, 0, 0, 0, 0, 0, 0, 0, -149, 0, 0, 0, 0, 0,0, 0, 0, 0, -471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -257, 0, 0, 0, 0, 0, 0, 0, 0, 0, 323, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 0, 0, 0, 0, 0, 0, 0, 0, 0, -263, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 151, 0, 0, 0, 0, 0, 0, 0, 0, 0, -43,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0, -313, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -495, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -295, 0, 0, 0, 0, 0, 0, 0, 0, 0, -105, 0, 0, 0, 0, 0, 0, 0, 0, 0, -451, 0, 0, 0, 0, 0, 0, 0, 0, 0, -371, 0, 0, 0, 0, 0]
    IFRA = [
        1, 0, 0, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 485, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        201, 0, 0, 0, 0, 0, 0, 0, 0, 0, -369, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        279, 0, 0, 0, 0, 0, 0, 0, 0, 0, 489, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 507,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -61, 0, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -171, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -321, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -145, 0, 0, 0, 0, 0, 0, 0, 0, 0, -433, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, -209, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 0, 0, 0, 0, 0,
        0, 0, 0, 0, -173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -251, 0, 0, 0, 0, 0, 0,
        0, 0, 0, -299, 0, 0, 0, 0, 0, 0, 0, 0, 0, -149, 0, 0, 0, 0, 0, 0, 0, 0,
        0, -471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -257, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 323, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 171, 0, 0, 0, 0, 0, 0, 0, 0, 0, -263, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 151, 0, 0, 0, 0, 0, 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0, -313, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, -495, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -295, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -105, 0, 0, 0, 0, 0, 0, 0, 0, 0, -451, 0, 0, 0, 0, 0, 0,
        0, 0, 0, -371, 0, 0, 0, 0, 0
    ]
    RDR = [
        175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 333, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -221, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, -535, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 507, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, -61, 0, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0, 0, 0, 0, 0, 0, 0, 0,
        0, -171, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -321, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, -145,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -433, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -209, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 0, 0, 0, 0, 0, 0, 0, 0, 0, -173, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -251, 0, 0, 0, 0, 0, 0, 0, 0, 0, -299, 0, 0,
        0, 0, 0, 0, 0, 0, 0, -149, 0, 0, 0, 0, 0, 0, 0, 0, 0, -471, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -257, 0, 0, 0, 0, 0, 0, 0, 0, 0, 323, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -263, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 151,
        0, 0, 0, 0, 0, 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 177, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -313, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -495, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -295, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -105, 0, 0, 0, 0, 0, 0, 0, 0, 0, -451, 0, 0, 0, 0, 0, 0, 0, 0, 0, -371,
        0, 0, 0, 0, 0
    ]
    naf = [
        1, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, 1, 0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
        0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, -1, 0, 0, 0,
        -1, 0, 0, 0, -1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0,
        0, 0, 0, -1, 0, 0, 0, 1, 0, -1, 0, 0, -1, 0, -1, 0, 1, 0, 0, -1, 0, -1,
        0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, -1, 0, 1, 0,
        0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1,
        0, 0, -1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, -1, 0, 1, 0, -1, 0,
        0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, -1, 0, -1, 0, 1, 0, 1, 0,
        1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1,
        0, 1, 0, 0, -1, 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0,
        0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 1, 0, -1, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, -1, 0,
        -1, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, -1,
        0, 0, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, -1, 0, -1, 0, 0,
        0, 1, 0, -1, 0, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1,
        0, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, 1, 0, 0, -1, 0, 1, 0, -1,
        0, -1, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 1, 0, 0, 1, 0, -1, 0, 1,
        0, 0, 0, 0, 0
    ]
    wnaf = l_naf.find_naf(
        d, 2,
        get_Wn(digit_set) + 2
    )  #[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 485, 0, 0, 0, 0, 0, 0, 0, 0, 0, 201, 0, 0, 0, 0, 0, 0, 0, 0, 0, -369, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 279, 0, 0, 0, 0, 0, 0, 0, 0, 0, 489, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -61, 0, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0, 0, 0, 0, 0, 0, 0, 0, 0, -171, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -321, 0, 0, 0, 0, 0, 0, 0, 0, 0, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, -145, 0, 0, 0, 0, 0, 0, 0, 0, 0, -433, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -209, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 0, 0, 0, 0, 0, 0, 0, 0, 0, -173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -251, 0, 0, 0, 0, 0, 0, 0, 0, 0, -299, 0, 0, 0, 0, 0, 0, 0, 0, 0, -149, 0, 0, 0, 0, 0, 0, 0, 0, 0, -471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -257, 0, 0, 0, 0, 0, 0, 0, 0, 0, 323, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 0, 0, 0, 0, 0, 0, 0, 0, 0, -263, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 151, 0, 0, 0, 0, 0, 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0, -313, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -495, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -295, 0, 0, 0, 0, 0, 0, 0, 0, 0, -105, 0, 0, 0, 0, 0, 0, 0, 0, 0, -451, 0, 0, 0, 0, 0, 0, 0, 0, 0, -371, 0, 0, 0, 0, 0]
    naf_set = []
    naf_set.append(1)
    i = 3
    while (i <= (2**(get_Wn(digit_set) + 1))):
        naf_set.append(i)
        i = i + 2
    i = 100

    doubleadd_time = 0
    naf_time = 0
    rdr_time = 0
    wnaf_time = 0
    ifra_time = 0
    while (i > 0):
        # print i
        startTime = time.time()
        Q = d * p384
        endTime = time.time()
        doubleadd_time = doubleadd_time + (endTime - startTime)
        # print("Double and add > ", endTime - startTime)

        startTime = time.time()
        G = p384.RDR_multiply_index(digit_set, RDR, i)
        endTime = time.time()
        rdr_time = rdr_time + (endTime - startTime)
        # print("RDR > ", endTime - startTime)

        startTime = time.time()
        X = p384.IFRDR_multiply_index(digit_set, IFRA, i)
        endTime = time.time()
        ifra_time = ifra_time + (endTime - startTime)

        startTime = time.time()
        N = p384.NAF_multiply(naf)
        endTime = time.time()
        naf_time = naf_time + (endTime - startTime)
        # print("NAF > ", endTime - startTime)

        startTime = time.time()
        W = p384.wnaf_multiply_index(naf_set, wnaf, i)
        endTime = time.time()
        wnaf_time = wnaf_time + (endTime - startTime)

        i = i - 1

    print("Double and Add average > ", doubleadd_time / 100)
    print("RDR average > ", rdr_time / 100)
    print("IFRA average > ", ifra_time / 100)
    print("NAF average > ", naf_time / 100)
    print("wNAF average > ", wnaf_time / 100)

    print("N > ", N.y())
    print("G > ", G.y())
    print("X > ", X.y())
    print("Q > ", Q.y())
    print("W > ", W.y())
def curve256():
    # NSIT Curve P-256
    p = 115792089210356248762697446949407573530086143415290314195533631308867097853951
    r = 115792089210356248762697446949407573529996955224135760342422259061068512044369
    #SEED = 0xc49d360886e704936a6678e1139d26b7819f7e90
    # c = 0x7efba1662985be9403cb055c75d4f7e0ce8d84a9c5114abcaf3177680104fa0d
    b = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b
    Gx = 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296
    Gy = 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5

    c256 = CurveFp(p, -3, b)
    p256 = Point(c256, Gx, Gy, r)

    d = 115792089210351248362697456949407573528996955234135760342422159061068512044339
    # Checking againtest_doublest some sample computations presented
    # in X9.62:
    digit_set = [
        1, 5, 17, 19, 27, 35, 37, 67, 79, 85, 91, 109, 111, 127, 131, 133, 139,
        149, 171, 179, 183, 199, 213, 227, 243, 247, 277, 283, 285, 297
    ]
    # IFRA = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, -133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, -183, 0, 0, 0, 0, 0, 0, 0, -139, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 243, 0, 0, 0, 0, -199, 0, 0, 0, 0, 0, 79, 0, 0, 0, 0, 0, 0, -79, 0, 0, 0, 0, 0, 79, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -127, 0, 0, 0, 0, 0, 79, 0, 0, 0, 0, 0, 109, 0, 0, 0, 0, 1, 0,0, 0, 0, 0, 0, 0, 0, 0, -91, 0, 0, 0, 0, 0, 0, 0, 0, -199, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -67, 0, 0, 0, 0, 0, 0, 0, 179, 0, 0, 0, 0, 0, 0, 0, -183, 0, 0, 0, 0, 0, 0, 179]
    IFRA = [
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0,
        0, 0, 0, 0, 0, 0, -133, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 5, 0, 0,
        0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, -227, 0, 0, 0, 0, 0, 0, 0, 0, 131, 0,
        0, 0, 0, 0, 0, 0, 109, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, -227, 0, 0, 0,
        0, 0, 0, -27, 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 17, 0,
        0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
        0, 0, 1, 0, 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, -17, 0, 0, 0, 0, 1, 0, 0,
        0, 0, 0, 0, 0, -111, 0, 0, 0, -5, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
        -227, 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, -1, 0, 0, 0, 0, 0, 0, 79, 0, 0, 0,
        0, 17, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -37, 0, 0, 1, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 297, 0, 0, 0, 0, 19
    ]
    RDR = [
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0,
        0, 0, 0, 0, 0, 0, -133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 0,
        0, 0, 0, 0, 0, -183, 0, 0, 0, 0, 0, 0, 0, -139, 0, 0, 0, 0, 0, 0, 0, 5,
        0, 0, 0, 0, 0, 0, 243, 0, 0, 0, 0, -199, 0, 0, 0, 0, 0, 79, 0, 0, 0, 0,
        0, 0, -79, 0, 0, 0, 0, 0, 79, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 199, 0, 0,
        0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -127, 0, 0, 0, 0, 0, 79, 0, 0, 0, 0, 0, 109, 0, 0, 0, 0, 1, 0, 0, 0, 0,
        0, 0, 0, 0, 0, -91, 0, 0, 0, 0, 0, 0, 0, 0, -199, 0, 0, 0, 0, 127, 0,
        0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -67, 0, 0, 0, 0, 0, 0, 0, 179, 0, 0,
        0, 0, 0, 0, 0, -183, 0, 0, 0, 0, 0, 0, 179
    ]
    naf = [
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1,
        0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 1, 0, 1, 0,
        0, 1, 0, 0, 0, 1, 0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0,
        -1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0, 1, 0, 0, -1, 0, 1, 0, -1, 0, 0, 1,
        0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0,
        0, 0, 0, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
        0, -1, 0, -1, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
        0, 0, 1, 0, -1, 0, -1, 0, 1, 0, 0, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, 1, 0,
        0, 1, 0, 1, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0,
        0, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0,
        -1, 0, 1, 0, -1
    ]
    wnaf = l_naf.find_naf(
        d, 2,
        get_Wn(digit_set) + 2
    )  #[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -159, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0, -147, 0, 0, 0, 0, 0, 0, 0, 0, 0, -185, 0, 0, 0, 0, 0, 0, 0, 0, 0, 201, 0, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 179, 0, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 0, 0, 0, 0, -91, 0, 0, 0, 0, 0, 0, 0, 0, -195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -119, 0, 0, 0, 0, 0, 0, 0, 0, 0, -37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 147, 0, 0, 0, 0, 0, 0, 0, 0, -205]
    naf_set = []
    naf_set.append(1)
    i = 3
    while (i <= (2**(get_Wn(digit_set) + 1))):
        naf_set.append(i)
        i = i + 2
    i = 100

    doubleadd_time = 0
    naf_time = 0
    rdr_time = 0
    wnaf_time = 0
    ifra_time = 0
    while (i > 0):
        # print i
        startTime = time.time()
        Q = d * p256
        endTime = time.time()
        doubleadd_time = doubleadd_time + (endTime - startTime)
        # print("Double and add > ", endTime - startTime)

        startTime = time.time()
        G = p256.RDR_multiply_index(digit_set, RDR, i)
        endTime = time.time()
        rdr_time = rdr_time + (endTime - startTime)
        # print("RDR > ", endTime - startTime)

        startTime = time.time()
        X = p256.IFRDR_multiply_index(digit_set, IFRA, i)
        endTime = time.time()
        ifra_time = ifra_time + (endTime - startTime)

        startTime = time.time()
        N = p256.NAF_multiply(naf)
        endTime = time.time()
        naf_time = naf_time + (endTime - startTime)
        # print("NAF > ", endTime - startTime)

        startTime = time.time()
        W = p256.wnaf_multiply_index(naf_set, wnaf, i)
        endTime = time.time()
        wnaf_time = wnaf_time + (endTime - startTime)

        i = i - 1

    print("Double and Add average > ", doubleadd_time / 100)
    print("RDR average > ", rdr_time / 100)
    print("IFRA average > ", ifra_time / 100)
    print("NAF average > ", naf_time / 100)
    print("wNAF average > ", wnaf_time / 100)

    print("N > ", N.y())
    print("G > ", G.y())
    print("X > ", X.y())
    print("Q > ", Q.y())
    print("W > ", W.y())
def curve224():
    # NIST Curve P-224:
    p = 26959946667150639794667015087019630673557916260026308143510066298881
    r = 26959946667150639794667015087019625940457807714424391721682722368061
    #SEED = bd713447 99d5c7fc dc45b59f a3b9ab8f 6a948bc5
    # c = 0x5b056c7e11dd68f40469ee7f3c7a7d74f7d121116506d031218291fb
    b = 0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4
    Gx = 0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21
    Gy = 0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34

    c244 = CurveFp(p, -3, b)
    p244 = Point(c244, Gx, Gy, r)

    d = 2695995667150639794667015087019625940457807714424391721682712368051
    # Checking againtest_doublest some sample computations presented
    # in X9.62:
    rdr_digit_set = [
        1, 21, 45, 87, 137, 143, 153, 155, 159, 165, 169, 171, 173, 199, 213,
        219, 223, 241, 267, 279, 281, 313, 329, 365, 379, 409, 419, 427, 445,
        455, 465, 467, 473, 493
    ]
    digit_set = [
        1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
        39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73,
        75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107,
        109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135,
        137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163,
        165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191,
        193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219,
        221, 223, 225, 227, 229, 231, 233, 235, 237, 239, 243, 245, 247, 249,
        251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277,
        279, 281, 283, 285, 287, 289, 291, 293, 295, 297, 299, 301, 303, 305,
        307, 309, 311, 313, 315, 317, 319, 321, 323, 325, 327, 329, 331, 333,
        335, 337, 339, 341, 343, 345, 347, 349, 351, 353, 355, 357, 359, 361,
        363, 365, 367, 369, 371, 373, 375, 377, 379, 381, 383, 385, 387, 389,
        391, 393, 395, 397, 399
    ]
    # IFRA = [51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, -185, 0, 0, 0, 0, 0, 0, 0, 0, 0, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, -261, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -399, 0, 0,0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, -377, 0, 0, 0, 0, 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 323, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 275, 0, 0, 0, 0, 0, 0, 0, 0, 0, 347, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 287, 0, 0, 0, 0, 0, 0, 0, 0, 0, -91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 325, 0, 0, 0, 0, 0, 0, 0, 0, 0, 367, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0,0, 0, -77]
    IFRA = [
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 0,
        0, 0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0,
        0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 251, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 227, 0, 0, 0, 0, 0, 0, 0, 0, 113, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0, 0, 97, 0, 0, 0, 0, 0,
        0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, -33, 0, 0, 0, 0, 0, 0, 0, 0,
        -189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, -169,
        0, 0, 0, 0, 0, 0, 0, 0, -119, 0, 0, 0, 0, 0, 0, 0, 0, -17, 0, 0, 0, 0,
        0, 0, 0, 0, -215, 0, 0, 0, 0, 0, 0, 0, 0, 139, 0, 0, 0, 0, 0, 0, 0, 0,
        -145, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        -77
    ]
    RDR = [
        51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, -185, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 265, 0, 0, 0,
        0, 0, 0, 0, 0, 0, -261, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -399, 0, 0, 0, 0, 0, 0, 0,
        0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, -377,
        0, 0, 0, 0, 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 323, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 275, 0, 0, 0, 0, 0, 0, 0, 0, 0, 347, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 287, 0, 0, 0, 0, 0, 0, 0, 0, 0, -91, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 325, 0, 0, 0, 0, 0, 0, 0, 0, 0, 367, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0, 0, 0, -77
    ]
    naf = [
        1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0,
        0, 1, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0,
        0, 1, 0, -1, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0,
        0, 0, 1, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1,
        0, 0, -1, 0, 0, 1, 0, 1, 0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,
        0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 1, 0, -1,
        0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1,
        0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 1, 0,
        0, 1, 0, 1, 0, 0, 1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0,
        0, 1, 0, 0, -1, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, -1, 0, 1, 0, -1
    ]
    wnaf = l_naf.find_naf(
        d, 2,
        get_Wn(digit_set) + 2
    )  #[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 0, 0, 0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 251, 0, 0, 0, 0, 0, 0, 0, 0, -63, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 227, 0, 0, 0, 0, 0, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0, 0, 97, 0, 0, 0, 0, 0, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, -33, 0, 0, 0, 0, 0, 0, 0, 0, -189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, -169, 0, 0, 0, 0, 0, 0, 0, 0, -119, 0, 0, 0, 0, 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, -215, 0, 0, 0, 0, 0, 0, 0, 0, 139, 0, 0, 0, 0, 0, 0, 0, 0, -145, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 0, 0, 0, 0, 0, 0, 0, 0, 0, -77]
    naf_set = []
    naf_set.append(1)
    i = 3
    while (i <= (2**(get_Wn(digit_set) + 1))):
        naf_set.append(i)
        i = i + 2
    i = 100

    doubleadd_time = 0
    naf_time = 0
    rdr_time = 0
    wnaf_time = 0
    ifra_time = 0
    while (i > 0):
        # print i
        startTime = time.time()
        Q = d * p244
        endTime = time.time()
        doubleadd_time = doubleadd_time + (endTime - startTime)
        # print("Double and add > ", endTime - startTime)

        startTime = time.time()
        G = p244.RDR_multiply_index(digit_set, RDR, i)
        endTime = time.time()
        rdr_time = rdr_time + (endTime - startTime)
        # print("RDR > ", endTime - startTime)

        startTime = time.time()
        X = p244.IFRDR_multiply_index(digit_set, IFRA, i)
        endTime = time.time()
        ifra_time = ifra_time + (endTime - startTime)

        startTime = time.time()
        N = p244.NAF_multiply(naf)
        endTime = time.time()
        naf_time = naf_time + (endTime - startTime)
        # print("NAF > ", endTime - startTime)

        startTime = time.time()
        W = p244.wnaf_multiply_index(naf_set, wnaf, i)
        endTime = time.time()
        wnaf_time = wnaf_time + (endTime - startTime)
        i = i - 1

    print("Double and Add average > ", doubleadd_time / 100)
    print("RDR average > ", rdr_time / 100)
    print("IFRA average > ", ifra_time / 100)
    print("NAF average > ", naf_time / 100)
    print("wNAF average > ", wnaf_time / 100)

    print("N > ", N.y())
    print("G > ", G.y())
    print("X > ", X.y())
    print("Q > ", Q.y())
    print("W > ", W.y())
def curve192():
    # NIST Curve P-192:
    p = 6277101735386680763835789423207666416083908700390324961279
    r = 6277101735386680763835789423176059013767194773182842284081
    # s = 0x3045ae6fc8422f64ed579528d38120eae12196d5L
    # c = 0x3099d2bbbfcb2538542dcd5fb078b6ef5f3d6fe2c745de65
    b = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1
    Gx = 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012
    Gy = 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811

    c192 = CurveFp(p, -3, b)
    p192 = Point(c192, Gx, Gy, r)

    d = 651056770906015076056810763456358567190100156695615665659
    # Checking againtest_doublest some sample computations presented
    # in X9.62:
    digit_set = [
        1, 23, 27, 43, 47, 49, 53, 57, 69, 95, 103, 113, 117, 129, 153, 155,
        171, 173, 175, 187, 191, 199, 213, 215, 239, 247, 271, 275, 281, 297,
        303, 315, 321, 327, 339, 349, 369, 383, 391
    ]
    # IFRA = [53, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 0, 0, 0, -175, 0, 0, 0, 0, 349, 0, 0, 0, 0, 0, 69, 0, 0, 0, 0, 0, 187, 0, 0, 0, 0, 0, 0, 0, 0, 47, 0, 0, 0, 0, -349, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -213, 0, 0, 0, 0, 0, 0, 0, 327, 0, 0, 0, 0, 0, 0, -349, 0, 0, 0, 0, 0, 0, 0, 0, 187, 0, 0, 0, 0, 0, 0,0, 0, -57, 0, 0, 0, 0, 0, 0, 297, 0, 0, 0, 0, 0, 0, 339, 0, 0, 0, 0, 0, 0, 0, -391, 0, 0, 0, 0, 0, 0, -391, 0, 0, 0, 0, 0, 0, -391, 0, 0,0, 0, 0, -247, 0, 0, 0, 0, 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, 187]
    IFRA = [
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -175, 0, 0, 0, 0, 0, 0, 0, 171, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 199, 0, 0, 0, 0, 0, 0, 113, 0, 0, 0, 0, 0, -43, 0, 0,
        0, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 271, 0, 0, 0, 0, 27, 0, 0, 1,
        0, -1, 0, 0, 0, 0, 0, 0, 0, -191, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
        27, 0, 0, 0, 0, 0, 0, 0, 0, -53, 0, 1, 0, 0, 0, 0, -23, 0, 0, 0, 0, 0,
        0, 0, 0, -239, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 175, 0, 0, 0, 0,
        -23, 0, 0, 0, 0, 0, 0, 0, 0, 175, 0, 0, 0, 0, 0, 0, 0, -117, 0, 0, 0,
        0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 215, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, -23,
        0, -1, 0, 0, 0, 0, 0, 0, 0, 175, 0, 0, 0, 0, 27
    ]
    naf = [
        1, 0, -1, 0, 1, 0, 1, 0, 0, 1, 0, 0, -1, 0, -1, 0, -1, 0, -1, 0, 1, 0,
        -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, -1, 0, -1, 0, 0, -1,
        0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 1,
        0, 0, 1, 0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 1, 0, -1, 0, 0, -1, 0, -1,
        0, 0, -1, 0, 1, 0, -1, 0, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
        1, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 1, 0, 1, 0, -1,
        0, -1, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0,
        0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,
        -1, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, -1
    ]
    wnaf = l_naf.find_naf(
        d, 2,
        get_Wn(digit_set) + 2
    )  #[425, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -339, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -449, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -39, 0, 0, 0, 0, 0, 0, 0, 0, 0, -447, 0, 0, 0, 0, 0, 0, 0, 0, 0, -245, 0, 0, 0, 0, 0, 0, 0, 0, 0, 371, 0, 0, 0, 0, 0, 0, 0, 0, 0, -239, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 141, 0, 0, 0, 0, 0, 0, 0, 0, 0, 471, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 299, 0, 0, 0, 0, 0, 0, 0, 0, 0, -93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -161, 0, 0, 0, 0, 0, 0, 0, 0, 0, -267, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 285, 0, 0, 0, 0, 0, 0, 0, 0, 0, 507]
    RDR = [
        53, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, -153, 0, 0, 0, 0,
        0, 0, -95, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 0, 0, 0, -175, 0, 0, 0,
        0, 349, 0, 0, 0, 0, 0, 69, 0, 0, 0, 0, 0, 187, 0, 0, 0, 0, 0, 0, 0, 0,
        47, 0, 0, 0, 0, -349, 0, 0, 0, 0, 0, -95, 0, 0, 0, 0, 0, 27, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, -213, 0, 0, 0, 0, 0, 0, 0, 327, 0, 0, 0, 0, 0, 0,
        -349, 0, 0, 0, 0, 0, 0, 0, 0, 187, 0, 0, 0, 0, 0, 0, 0, 0, -57, 0, 0,
        0, 0, 0, 0, 297, 0, 0, 0, 0, 0, 0, 339, 0, 0, 0, 0, 0, 0, 0, -391, 0,
        0, 0, 0, 0, 0, -391, 0, 0, 0, 0, 0, 0, -391, 0, 0, 0, 0, 0, -247, 0, 0,
        0, 0, 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, 187
    ]

    naf_set = []
    naf_set.append(1)
    i = 3
    while (i <= (2**(get_Wn(digit_set) + 1))):
        naf_set.append(i)
        i = i + 2
    # print naf_set
    i = 100

    doubleadd_time = 0
    naf_time = 0
    rdr_time = 0
    wnaf_time = 0
    ifra_time = 0
    while (i > 0):
        # print i
        startTime = time.time()
        Q = d * p192
        endTime = time.time()
        doubleadd_time = doubleadd_time + (endTime - startTime)
        # print("Double and add > ", endTime - startTime)

        startTime = time.time()
        G = p192.RDR_multiply_index(digit_set, RDR, i)
        endTime = time.time()
        rdr_time = rdr_time + (endTime - startTime)
        # print("RDR > ", endTime - startTime)

        startTime = time.time()
        X = p192.IFRDR_multiply_index(digit_set, IFRA, i)
        endTime = time.time()
        ifra_time = ifra_time + (endTime - startTime)

        startTime = time.time()
        N = p192.NAF_multiply(naf)
        endTime = time.time()
        naf_time = naf_time + (endTime - startTime)
        # print("NAF > ", endTime - startTime)

        startTime = time.time()
        W = p192.wnaf_multiply_index(naf_set, wnaf, i)
        endTime = time.time()
        wnaf_time = wnaf_time + (endTime - startTime)

        i = i - 1

    print("Double and Add average > ", doubleadd_time / 100)
    print("RDR average > ", rdr_time / 100)
    print("IFRA average > ", ifra_time / 100)
    print("NAF average > ", naf_time / 100)
    print("wNAF average > ", wnaf_time / 100)

    print("N > ", N.y())
    print("G > ", G.y())
    print("X > ", X.y())
    print("Q > ", Q.y())
    print("W > ", W.y())