Beispiel #1
0
def test_InvModHex(test_data_dir):

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

        for x in invModHex_txt:

            hexNumber = x.split(",")

            # Inverse modulo of big numbers of arbitrary precision in hex
            actual_value = PyBigNumbers.Inv_mod_Hex(hexNumber[0], hexNumber[1])
            expected_value = hexNumber[2].rstrip("\n")

            #verifying the actual value with the expected value
            assert actual_value.lstrip(
                "0") == expected_value.upper(), "Test failed"
Beispiel #2
0
 def inverse(self):
     if (self.isDec):
         if (self.mod is None):
             numerator = BigNumber('1', self.mod, self.isDec)
             inverseVal = numerator / self
         else:
             inverseVal = PyBigNumbers.Inv_mod_Dec(self.value, self.mod)
         retVal = BigNum(inverseVal, self.mod, self.isDec)
         return retVal
     else:
         if (self.mod is None):
             numerator = BigNumber('1', self.mod)
             inverseVal = numberator % self
         else:
             inverseVal = PyBigNumbers.Inv_mod_Hex(self.value, self.mod)
         retVal = BigNum(inverseVal, self.mod, self.isDec)
         return retVal