示例#1
0
def test_LGInterpolatorSingleHex():

    listTupleObj = [(1, "13"), (2, "4"), (3, "2"), (4, "5"), (5, "11"),
                    (6, "1")]
    modulo = str(1238275102653497496038888277977)
    hex_value = 0
    xValue = str(randint(10, 100000))
    for x in range(1, 6):
        xPoint = str(x)
        # LGInterpolator, evaluate the ith basis polynomial at xValue
        lgInterpolatorX = Nakasendo.LGInterpolator(listTupleObj, modulo,
                                                   hex_value)
        lgInterpolatorX = lgInterpolatorX(xValue, xPoint)
        assert type(lgInterpolatorX) == Nakasendo.BigNum, "Test failed"
示例#2
0
def test_LGInterpolatorSingleDec():

    listTupleObj = [(1, "13"), (2, "4"), (3, "2"), (4, "5"), (5, "11"),
                    (6, "1")]
    modulo = str(1166395137945795428855301183413)
    dec = 1
    xValue = str(randint(10, 100000))

    for x in range(1, 6):
        xPoint = str(x)

        # LGInterpolator, evaluate the ith basis polynomial at xValue
        lgInterpolatorX = Nakasendo.LGInterpolator(listTupleObj, modulo, dec)
        lgInterpolatorX = lgInterpolatorX(xValue, xPoint)
        assert type(lgInterpolatorX) == Nakasendo.BigNum, "Test failed"
示例#3
0
def test_LGInterpolatorFullDec():

    listTupleObj = [(2, "10"), (3, "15")]
    modulo = "0"
    dec = 1

    for x in range(100, 101):
        randomX = randint(1000, 1000000)
        xValue = str(randomX)

        # LGInterpolator, full evaluation of the polynomial at xValue
        lgInterpolatorX = Nakasendo.LGInterpolator(listTupleObj, modulo, dec)
        lgInterpolatorX = lgInterpolatorX(xValue)
        TestVal = Nakasendo.BigNum(value=str(randomX * 5),
                                   mod=modulo,
                                   isDec=dec)
        assert lgInterpolatorX == TestVal, "Test failed"
示例#4
0
def test_LGInterpolatorFullHex():

    listTupleObj = [(2, "A"), (3, "F")]
    modulo = "0"
    hex_value = 0

    for x in range(100, 200):
        randomX = Nakasendo.BigNum()
        xValue = str(randomX.value)
        # LGInterpolator, full evaluation of the polynomial at xValue
        lgInterpolatorX = Nakasendo.LGInterpolator(listTupleObj, modulo,
                                                   hex_value)
        lgInterpolatorX = lgInterpolatorX(xValue)
        TestVal = Nakasendo.BigNum(value=hex(int(randomX.value, 16) *
                                             5).lstrip("0x").upper(),
                                   mod=modulo,
                                   isDec=hex_value)
        assert lgInterpolatorX == TestVal, "Test failed"
示例#5
0
    print('Public Key %s %s' % (PubKeyPoints[0], PubKeyPoints[1]))
    print('public key in compressed form %s' % HiddenPoint)
    print('private key %s' % secret.value)
    #can we recover the key from a subgroup with interpolation

    #Recover the public key from a t+1 group.
    print('Recover the public/private key pair from a group size of t+1 = %s' %
          (tt + 1))
    private_d_points = []
    for i in subGroupPlayersIndex:
        label_j = Players[i].getOrdinal()
        d_j = vect_d[i]
        private_d_points.append((int(label_j), d_j.value))

    private_d_interpolator = Nakasendo.LGInterpolator(private_d_points,
                                                      modulo_n.value,
                                                      decimal=False)
    vect_DG = [
    ]  ## Precalculate for each player j the interpolated value   L_j(0) * k_j *G. The sum of this will give k*G

    for i in range(len(private_d_points)):
        interpVal = private_d_interpolator('0', str(i))
        djBN = Nakasendo.BigNum(private_d_points[i][1], modulo_n, isDec=False)
        KInterpVal = interpVal * djBN
        KGVal = GENPOINT.multipleScalar(KInterpVal)
        vect_DG.append(KGVal)

    #print(vect_KG)

    keySum = vect_DG[0]
    for vals in vect_DG[1:len(vect_DG)]:
示例#6
0
    # using polyDecimal, setup xfx
    margin = 2
    npPoint = polyDecimal.degree + 1 + margin
    vectorX = []
    for x in range(npPoint):
        firstNum = 1
        secondNum = x
        firstNum = firstNum + secondNum
        vectorX.append(firstNum)

    xfx = []
    for x in vectorX:
        xfx.append((x, polyDecimal(str(x))))

    #create interpolator
    lgInterpolator = Nakasendo.LGInterpolator(xfx, polyDecimal.modulo,
                                              polyDecimal.isDec)
    print("lgInterpolator = ", lgInterpolator)

    xValue = random.randint(0, int(lgInterpolator.modulo) - 1)
    basisPoint = random.randint(0, len(lgInterpolator.points) - 1)

    print("xValue = %s, basisPoint = %s" % (xValue, basisPoint))
    value = lgInterpolator(str(xValue))
    print("Full LG Interpolation evaluation for xValue=%s is %s" %
          (xValue, value))
    valBasis = lgInterpolator(str(xValue), str(basisPoint))
    print ("LG Interpolation evaluation for %sth basis point where xValue=%s is %s" % \
        (basisPoint, xValue, valBasis ) )

    #---------------------------------------------------------------------------
    print(