def test_RandomPolynomialHex(): for x in range(5): fx = PyBigNumbers.GenerateRandHex(256) degree = randint(10, 15) modulo = PyBigNumbers.GenerateRandPrimeHex(100) hex_value = 0 # create a random polynomial listCoefficients = PyPolynomial.randomPolynomial( degree, modulo, 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"
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"
def test_GenerateRandPrimeHex(): #Generating prime decimal numbers with input parameter for x in range(10, 100, 10): # Generate Random Prime Number of arbitary precision in hex primeHex_Value = PyBigNumbers.GenerateRandPrimeHex(x) # Verifying the actual value as prime hex number or not assert PyBigNumbers.isPrimeHex(primeHex_Value), "Test failed"
def test_LGInterpolatorSingleHex(): listTupleObj = [(1, "13"), (2, "4"), (3, "2"), (4, "5"), (5, "11"), (6, "1")] modulo = PyBigNumbers.GenerateRandPrimeHex(100) 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 = PyPolynomial.LGInterpolatorSingle( listTupleObj, modulo, xValue, xPoint, hex_value) assert type(lgInterpolatorX) == str, "Test failed"
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"