コード例 #1
0
def test_InitFromListHex():

    hex_value = 0
    for x in range(10, 15):

        fx = PyBigNumbers.GenerateRandHex(256)
        modulo = PyBigNumbers.GenerateRandPrimeHex(100)
        listCoefficients = []

        for i in range(x):
            # Generate random coefficients for the polynomial
            listCoefficients.append(PyBigNumbers.GenerateRandHex(256))

        # create a Polynomial from a list of coefficients
        allCoeffeicient = PyPolynomial.initFromList(listCoefficients,
                                                    hex_value)
        assert len(allCoeffeicient) == x, "Test failed"

        # Calling evaluate polynomial function
        polynomialFX = polynomialEvaluation(listCoefficients, fx, modulo,
                                            hex_value)

        # convert list of coefficients from string to decimal
        lst = []
        for i in range(len(allCoeffeicient)):
            lst.append(int(allCoeffeicient[i], 16))

        fx = int(fx, 16)
        modulo = int(modulo, 16)
        actualValue = polynomial_evaluate(lst, fx, modulo)
        assert polynomialFX.lstrip("0") == hex(actualValue).upper().lstrip(
            "0X"), "Test failed"
コード例 #2
0
def test_RandomPolynomialMinMaxHex():

    for x in range(5):

        fx = PyBigNumbers.GenerateRandHex(256)
        degree = randint(10, 15)
        hex_value = 0
        modulo = str(randint(100000, 10000000))
        min = str(randint(10000, 10000000))
        max = str(randint(10000001, 100000000))

        # create a random polynomial with range of min..max
        listCoefficients = PyPolynomial.randomPolynomialMinMax(
            degree, modulo, min, max, hex_value)
        assert len(listCoefficients) == (degree + 1), "Test failed"

        # calling evaluate polynomial function
        polynomialFX = polynomialEvaluation(listCoefficients, fx, modulo,
                                            hex_value)

        # convert list of coefficients from string to decimal
        lst = []
        for i in range(len(listCoefficients)):
            lst.append(int(listCoefficients[i], 16))

        fx = int(fx, 16)
        modulo = int(modulo, 16)
        actualValue = polynomial_evaluate(lst, fx, modulo)
        assert polynomialFX.lstrip("0") == hex(actualValue).upper().lstrip(
            "0X"), "Test failed"
コード例 #3
0
def test_InitFromListModuloHex():

    for x in range(10, 15):

        modHex = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
        fx = PyBigNumbers.GenerateRandHex(256)
        degree = randint(10, 15)
        hex_value = 0

        # create a random polynomial
        listCoefficients = PyPolynomial.randomPolynomial(
            degree, modHex, hex_value)
        assert len(listCoefficients) == (degree + 1), "Test failed"

        # create a Polynomial from a list of coefficient with modulo
        coefficientsWithModulo = PyPolynomial.initFromListModulo(
            listCoefficients, modHex, hex_value)
        assert len(coefficientsWithModulo) == degree + 1, "Test failed"

        # calling evaluate polynomial function
        polynomialFX = polynomialEvaluation(coefficientsWithModulo, fx, modHex,
                                            hex_value)

        # convert list of coefficients from string to decimal
        lst = []
        for i in range(len(coefficientsWithModulo)):
            lst.append(int(coefficientsWithModulo[i], 16))

        fx = int(fx, 16)
        modulo = int(modHex, 16)
        actualValue = polynomial_evaluate(lst, fx, modulo)
        assert polynomialFX.lstrip("0") == hex(actualValue).upper().lstrip(
            "0X"), "Test failed"
コード例 #4
0
ファイル: Nakasendo.py プロジェクト: hilzlee/nakasendo-1
    def __init__(self, value=None, mod=None, isDec=False):
        self.mod = mod
        self.isDec = isDec

        if value is None:
            if (self.isDec):
                self.value = PyBigNumbers.GenerateRandDec(256)
            else:
                self.value = PyBigNumbers.GenerateRandHex(256)
        else:
            self.value = value
コード例 #5
0
def test_GenRandHex(test_data_dir):

    # Reading test data from the file
    with open(test_data_dir / "testData_GenBigNum", "r") as genHex_txt:

        for x in genHex_txt.readlines():

            decNumber = int(x)
            # Generate Random Number of arbitrary precision in dec
            actual_Value = PyBigNumbers.GenerateRandHex(decNumber)

            #Verifying the actual value as a string and not negative value
            assert type(
                actual_Value) is str and actual_Value != "-1", "Test failed"
コード例 #6
0
def test_LGInterpolatorFullHex():

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

    for x in range(100, 110):
        randomX = PyBigNumbers.GenerateRandHex(100000)
        xValue = str(randomX)
        # LGInterpolator, full evaluation of the polynomial at xValue
        lgInterpolatorX = PyPolynomial.LGInterpolatorFull(
            listTupleObj, modulo, xValue, hex_value)
        assert lgInterpolatorX.lstrip("0") == hex(
            int(randomX, 16) * 5).lstrip("0x").upper(), "Test failed"
コード例 #7
0
def test_LGECInterpolatorFull():

    modulo = PyBigNumbers.GenerateRandPrimeHex(1000)
    xValue = PyBigNumbers.GenerateRandHex(1000)
    listTupleObj = []
    dec = False

    # Generating Random EC
    for x in range(10, 50):
        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint()

        # Check if the point is on the curve with the supplied NID default NID ==> NID_secp256k1
        assert hexValue.IsPointOnCurve(), "Test failed"

        x_Axis, y_axis = hexValue.GetAffineCoOrdinates()
        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        listTupleObj.append((str(x), x_Axis, y_axis))

    lgInterpolatorX = PyPolynomial.LGECInterpolatorFull(
        listTupleObj, modulo, xValue, dec)
    assert type(lgInterpolatorX) == str, "Test failed"