コード例 #1
0
 def test_unencoded(self, args):
     blob = args[0]
     hyp.assume(len(blob) != 0)
     string = args[1]
     with pytest.raises(TypeError):
         bf.hamming_distance(string, blob)
     with pytest.raises(TypeError):
         bf.hamming_distance(blob, string)
コード例 #2
0
def _rate_repeating_xor_keysize(ciphertext, size):
    block1 = ciphertext[:size]
    block2 = ciphertext[size:2 * size]
    return hamming_distance(block1, block2) / size
コード例 #3
0
 def test_hamming_distance(self):
     assert bf.hamming_distance(b"this is a test", b"wokka wokka!!!") == 37
コード例 #4
0
 def test_example_distances(self):
     assert bf.hamming_distance(b"bla", b"alb") == 4
     assert bf.hamming_distance(b"bla", b"BLA") == 3
     assert bf.hamming_distance([1, 2, 3], [0, 5, 5]) == 6
コード例 #5
0
 def test_subadditive(self, list_):
     dist01 = bf.hamming_distance(list_[0], list_[1])
     dist12 = bf.hamming_distance(list_[1], list_[2])
     dist02 = bf.hamming_distance(list_[0], list_[2])
     assert dist02 <= dist01 + dist12
コード例 #6
0
 def test_symmetrical(self, list_):
     left = list_[0]
     right = list_[1]
     assert bf.hamming_distance(left, right) == \
            bf.hamming_distance(right, left)
コード例 #7
0
 def test_identical(self, arg):
     assert bf.hamming_distance(arg, arg) == 0
コード例 #8
0
 def test_out_of_range(self, list_):
     hyp.assume(len(list_) != 0)
     with pytest.raises(ValueError):
         bf.hamming_distance(list_, list_)
コード例 #9
0
 def test_lists(self):
     assert bf.hamming_distance([1, 2, 3], [1, 2, 3]) == 0
コード例 #10
0
 def test_empty(self):
     assert bf.hamming_distance([], []) == 0
     assert bf.hamming_distance(b"", b"") == 0
コード例 #11
0
 def test_different_length(self, left, right):
     hyp.assume(len(left) != len(right))
     with pytest.raises(ValueError):
         bf.hamming_distance(left, right)