Пример #1
0
def xor_buffers(left, right):
    """Xor two bytes-like objects, repeating the shorter as needed"""
    return bytes(xor_pairs(repeating_zip(left, right)))
Пример #2
0
 def test_symmetrical(self, pairs):
     pairs = [pair for pair in pairs]
     flipped = [pair[::-1] for pair in pairs]
     assert list(bf.xor_pairs(pairs)) == list(bf.xor_pairs(flipped))
Пример #3
0
 def test_empty(self):
     assert list(bf.xor_pairs([])) == []
Пример #4
0
 def test_self_xor_yields_zero(self, ints):
     length = len(ints)
     pairs = [(el, el) for el in ints]
     result = list(bf.xor_pairs(pairs))
     should_be = [0] * length
     assert result == should_be
Пример #5
0
 def test_length_preserved(self, pairs):
     list_ = list(pairs)
     assert len(list_) == len(list(bf.xor_pairs(list_)))
Пример #6
0
 def test_known_values(self):
     pairs = [(1, 1), (7, 0), (3, 1), (512, 1), (-1, 3), (-7, 6)]
     result = list(bf.xor_pairs(pairs))
     assert result == [0, 7, 2, 513, -4, -1]
Пример #7
0
 def test_not_pairs(self):
     with pytest.raises(TypeError):
         list(bf.xor_pairs(iter([1, 2, 3])))
Пример #8
0
 def test_not_xorable(self):
     with pytest.raises(TypeError):
         list(bf.xor_pairs([(1, "bla"), (2, "blo"), (3, "bli")]))