def xor_buffers(left, right):
    """Xor two bytes-like objects, repeating the shorter as needed"""
    return bytes(xor_pairs(repeating_zip(left, right)))
Esempio n. 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))
Esempio n. 3
0
 def test_empty(self):
     assert list(bf.xor_pairs([])) == []
Esempio n. 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
Esempio n. 5
0
 def test_length_preserved(self, pairs):
     list_ = list(pairs)
     assert len(list_) == len(list(bf.xor_pairs(list_)))
Esempio n. 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]
Esempio n. 7
0
 def test_not_pairs(self):
     with pytest.raises(TypeError):
         list(bf.xor_pairs(iter([1, 2, 3])))
Esempio n. 8
0
 def test_not_xorable(self):
     with pytest.raises(TypeError):
         list(bf.xor_pairs([(1, "bla"), (2, "blo"), (3, "bli")]))