我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用Crypto.Util.number.exact_div()。
def __init__(self): self.counter = Counter.new(nbits=self.block_size*8, initial_value=0, little_endian=True) self.key = None # Set some helper constants self.block_size_shift = exact_log2(self.block_size) assert (1 << self.block_size_shift) == self.block_size self.blocks_per_key = exact_div(self.key_size, self.block_size) assert self.key_size == self.blocks_per_key * self.block_size self.max_bytes_per_request = self.max_blocks_per_request * self.block_size
def test_exact_div(self): """Util.number.exact_div""" # Positive numbers self.assertEqual(1, number.exact_div(1, 1)) self.assertRaises(ValueError, number.exact_div, 1, 2) self.assertEqual(1, number.exact_div(2, 2)) self.assertRaises(ValueError, number.exact_div, 3, 2) self.assertEqual(2, number.exact_div(4, 2)) # Negative numbers self.assertEqual(-1, number.exact_div(-1, 1)) self.assertEqual(-1, number.exact_div(1, -1)) self.assertRaises(ValueError, number.exact_div, -1, 2) self.assertEqual(1, number.exact_div(-2, -2)) self.assertEqual(-2, number.exact_div(-4, 2)) # Zero dividend self.assertEqual(0, number.exact_div(0, 1)) self.assertEqual(0, number.exact_div(0, 2)) # Zero divisor (allow_divzero == False) self.assertRaises(ZeroDivisionError, number.exact_div, 0, 0) self.assertRaises(ZeroDivisionError, number.exact_div, 1, 0) # Zero divisor (allow_divzero == True) self.assertEqual(0, number.exact_div(0, 0, allow_divzero=True)) self.assertRaises(ValueError, number.exact_div, 1, 0, allow_divzero=True)