def test_RandomPolynomialDec(): for x in range(5): fx = PyBigNumbers.GenerateRandDec(256) degree = randint(10, 15) modulo = PyBigNumbers.GenerateRandPrimeDec(100) dec = 1 # create a random polynomial listCoefficients = PyPolynomial.randomPolynomial(degree, modulo, dec) assert len(listCoefficients) == (degree + 1), "Test failed" # calling evaluate polynomial function polynomialFX = polynomialEvaluation(listCoefficients, fx, modulo, dec) # convert list of coefficients from string to decimal lst = [] for i in range(len(listCoefficients)): lst.append(int(listCoefficients[i])) fx = int(fx) modulo = int(modulo) actualValue = polynomial_evaluate(lst, fx, modulo) assert polynomialFX == str(actualValue), "Test failed"
def test_MultiplyScalarMNOnCurve(): # Generating Random EC Points for x in range(100): # Generate a Random EC Point with default NID ==> NID_secp256k1 ecPoint_value = PyECPoint.GenerateRandomEC(0, hex, True ) # Check if the point is on the curve with the supplied NID default NID ==> NID_secp256k1 assert PyECPoint.CheckOnCurve(ecPoint_value, 0, hex), "Test failed" #Generate a Random Big number M and N using BigNumberAPIs bigNumbM = PyBigNumbers.GenerateRandDec(257) bigNumbN = PyBigNumbers.GenerateRandDec(128) # EC Point Scalar multiply with supplied curve ID actual_value = PyECPoint.MultiplyScalarMN(ecPoint_value, bigNumbM, bigNumbN, nid_Id, hex, True) # Verifying the the length of actual value as 66 assert len(actual_value) == 66, "Test failed"
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
def test_GenRandDec(test_data_dir): # Reading test data from the file with open(test_data_dir / "testData_GenBigNum", "r") as genDec_txt: for x in genDec_txt.readlines(): decNumber = int(x) # Generate Random Number of arbitrary precision in dec actual_Value = PyBigNumbers.GenerateRandDec(decNumber) #Verifying the actual value as a string and not negative value assert type( actual_Value) is str and actual_Value != "-1", "Test failed"