我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用Crypto.Util.number.ceil_shift()。
def _pseudo_random_data(self, bytes): if not (0 <= bytes <= self.max_bytes_per_request): raise AssertionError("You cannot ask for more than 1 MiB of data per request") num_blocks = ceil_shift(bytes, self.block_size_shift) # num_blocks = ceil(bytes / self.block_size) # Compute the output retval = self._generate_blocks(num_blocks)[:bytes] # Switch to a new key to avoid later compromises of this output (i.e. # state compromise extension attacks) self._set_key(self._generate_blocks(self.blocks_per_key)) assert len(retval) == bytes assert len(self.key) == self.key_size return retval
def test_ceil_shift(self): """Util.number.ceil_shift""" self.assertRaises(AssertionError, number.ceil_shift, -1, 1) self.assertRaises(AssertionError, number.ceil_shift, 1, -1) # b = 0 self.assertEqual(0, number.ceil_shift(0, 0)) self.assertEqual(1, number.ceil_shift(1, 0)) self.assertEqual(2, number.ceil_shift(2, 0)) self.assertEqual(3, number.ceil_shift(3, 0)) # b = 1 self.assertEqual(0, number.ceil_shift(0, 1)) self.assertEqual(1, number.ceil_shift(1, 1)) self.assertEqual(1, number.ceil_shift(2, 1)) self.assertEqual(2, number.ceil_shift(3, 1)) # b = 2 self.assertEqual(0, number.ceil_shift(0, 2)) self.assertEqual(1, number.ceil_shift(1, 2)) self.assertEqual(1, number.ceil_shift(2, 2)) self.assertEqual(1, number.ceil_shift(3, 2)) self.assertEqual(1, number.ceil_shift(4, 2)) self.assertEqual(2, number.ceil_shift(5, 2)) self.assertEqual(2, number.ceil_shift(6, 2)) self.assertEqual(2, number.ceil_shift(7, 2)) self.assertEqual(2, number.ceil_shift(8, 2)) self.assertEqual(3, number.ceil_shift(9, 2)) for b in range(3, 1+129, 3): # 3, 6, ... , 129 self.assertEqual(0, number.ceil_shift(0, b)) n = 1L while n <= 2L**(b+2): (q, r) = divmod(n-1, 2L**b) expected = q + int(not not r) self.assertEqual((n-1, b, expected), (n-1, b, number.ceil_shift(n-1, b))) (q, r) = divmod(n, 2L**b) expected = q + int(not not r) self.assertEqual((n, b, expected), (n, b, number.ceil_shift(n, b))) (q, r) = divmod(n+1, 2L**b) expected = q + int(not not r) self.assertEqual((n+1, b, expected), (n+1, b, number.ceil_shift(n+1, b))) n *= 2
def test_ceil_shift(self): """Util.number.ceil_shift""" self.assertRaises(AssertionError, number.ceil_shift, -1, 1) self.assertRaises(AssertionError, number.ceil_shift, 1, -1) # b = 0 self.assertEqual(0, number.ceil_shift(0, 0)) self.assertEqual(1, number.ceil_shift(1, 0)) self.assertEqual(2, number.ceil_shift(2, 0)) self.assertEqual(3, number.ceil_shift(3, 0)) # b = 1 self.assertEqual(0, number.ceil_shift(0, 1)) self.assertEqual(1, number.ceil_shift(1, 1)) self.assertEqual(1, number.ceil_shift(2, 1)) self.assertEqual(2, number.ceil_shift(3, 1)) # b = 2 self.assertEqual(0, number.ceil_shift(0, 2)) self.assertEqual(1, number.ceil_shift(1, 2)) self.assertEqual(1, number.ceil_shift(2, 2)) self.assertEqual(1, number.ceil_shift(3, 2)) self.assertEqual(1, number.ceil_shift(4, 2)) self.assertEqual(2, number.ceil_shift(5, 2)) self.assertEqual(2, number.ceil_shift(6, 2)) self.assertEqual(2, number.ceil_shift(7, 2)) self.assertEqual(2, number.ceil_shift(8, 2)) self.assertEqual(3, number.ceil_shift(9, 2)) for b in range(3, 1+129, 3): # 3, 6, ... , 129 self.assertEqual(0, number.ceil_shift(0, b)) n = 1 while n <= 2**(b+2): (q, r) = divmod(n-1, 2**b) expected = q + int(not not r) self.assertEqual((n-1, b, expected), (n-1, b, number.ceil_shift(n-1, b))) (q, r) = divmod(n, 2**b) expected = q + int(not not r) self.assertEqual((n, b, expected), (n, b, number.ceil_shift(n, b))) (q, r) = divmod(n+1, 2**b) expected = q + int(not not r) self.assertEqual((n+1, b, expected), (n+1, b, number.ceil_shift(n+1, b))) n *= 2