def test_untemper_right_invert_tempering_without_and_mask(self): expected = 172233979 tempered = 172234346 # y ^ (y >> l) untempered = _untemper_right(tempered, 18, (1 << get_numbits(tempered)) - 1) self.assertEqual(expected, untempered)
def test_untemper_right_shift_half_bitsize(self): bits = 0xE shift = 2 mask = 0x1 tempered = self.temper_right(bits, shift, mask) untempered = _untemper_right(tempered, shift, mask) self.assertEqual(bits, untempered)
def test_untemper_right_smaller_than_bitshift(self): bits = 12 shift = 4 mask = 7 tempered = self.temper_right(bits, shift, mask) untempered = _untemper_right(tempered, shift, mask) self.assertEqual(bits, untempered)
def test_untemper_right_last_shift_results_in_smaller_block(self): bits = 0x1D shift = 2 mask = 0x1 tempered = self.temper_right(bits, shift, mask) untempered = _untemper_right(tempered, shift, mask) self.assertEqual(bits, untempered)
def test_untemper_right_negative_shift_raises(self): with self.assertRaises(ValueError): _untemper_right(12, -1, 7)