def __mul__(self, obj): if (self.isDec): if (self.mod is None): prodVal = PyBigNumbers.multiplyFromDec(self.value, obj.value) else: #print ('%s * %s mod %s' % (self.value, obj.value, self.mod)) prodVal = PyBigNumbers.Mul_mod_Dec(self.value, obj.value, self.mod) retVal = BigNum(prodVal, self.mod, self.isDec) return retVal else: if (self.mod is None): prodVal = PyBigNumbers.multiplyFromHex(self.value, obj.value) else: #print ('%s * %s mod %s' % (self.value, obj.value, self.mod)) prodVal = PyBigNumbers.Mul_mod_Hex(self.value, obj.value, self.mod) retVal = BigNum(prodVal, self.mod, self.isDec) return retVal
def test_MultiplyHex(test_data_dir): # Reading test data from the file with open(test_data_dir / "testData_MultiplyDec", "r") as multiplyHex_txt: for x in multiplyHex_txt: decNumber = x.split(",") #converting decimal to hex-decimal i = int(decNumber[0]) j = int(decNumber[1]) k = int(decNumber[2].rstrip("\n")) hex_Value = hex(i).lstrip("0x") hex_Value2 = hex(j).lstrip("0x") expected_Value = hex(k).lstrip("0x") # multiply two big numbers of arbitrary precision in hex actualValue = PyBigNumbers.multiplyFromHex(str(hex_Value), str(hex_Value2)) actual_Value = actualValue.lstrip("0") expectedValue = expected_Value.upper() # Verifying the actual value with expected value assert actual_Value == expected_Value.upper(), "Test failed"