我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用Crypto.Util.number.exact_log2()。
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_log2(self): """Util.number.exact_log2""" self.assertRaises(TypeError, number.exact_log2, "0") self.assertRaises(ValueError, number.exact_log2, -1) self.assertRaises(ValueError, number.exact_log2, 0) self.assertEqual(0, number.exact_log2(1)) self.assertEqual(1, number.exact_log2(2)) self.assertRaises(ValueError, number.exact_log2, 3) self.assertEqual(2, number.exact_log2(4)) self.assertRaises(ValueError, number.exact_log2, 5) self.assertRaises(ValueError, number.exact_log2, 6) self.assertRaises(ValueError, number.exact_log2, 7) e = 3 n = 8 while e < 16: if n == 2**e: self.assertEqual(e, number.exact_log2(n), "expected=2**%d, n=%d" % (e, n)) e += 1 else: self.assertRaises(ValueError, number.exact_log2, n) n += 1 for e in range(16, 1+64, 2): self.assertRaises(ValueError, number.exact_log2, 2L**e-1) self.assertEqual(e, number.exact_log2(2L**e)) self.assertRaises(ValueError, number.exact_log2, 2L**e+1)
def test_exact_log2(self): """Util.number.exact_log2""" self.assertRaises(TypeError, number.exact_log2, "0") self.assertRaises(ValueError, number.exact_log2, -1) self.assertRaises(ValueError, number.exact_log2, 0) self.assertEqual(0, number.exact_log2(1)) self.assertEqual(1, number.exact_log2(2)) self.assertRaises(ValueError, number.exact_log2, 3) self.assertEqual(2, number.exact_log2(4)) self.assertRaises(ValueError, number.exact_log2, 5) self.assertRaises(ValueError, number.exact_log2, 6) self.assertRaises(ValueError, number.exact_log2, 7) e = 3 n = 8 while e < 16: if n == 2**e: self.assertEqual(e, number.exact_log2(n), "expected=2**%d, n=%d" % (e, n)) e += 1 else: self.assertRaises(ValueError, number.exact_log2, n) n += 1 for e in range(16, 1+64, 2): self.assertRaises(ValueError, number.exact_log2, 2**e-1) self.assertEqual(e, number.exact_log2(2**e)) self.assertRaises(ValueError, number.exact_log2, 2**e+1)