示例#1
0
def get_vigenere_key_score(ciphertext, keysize, compare_blocks=4):
    """returns the score for this keysize on this text"""
    hdist = 0
    blocks = vigenere_blocks(ciphertext, keysize, compare_blocks)
    comparisons = 0
    for b1, b2 in itertools.combinations(blocks, 2):
        hdist += crypt_utils.hamming_distance(b1, b2)
        comparisons += 1

    hdist = hdist / comparisons

    return hdist / keysize
示例#2
0
 def test_hamming_distance(self):
     s1 = "this is a test"
     s2 = "wokka wokka!!!"
     h_dist = crypt_utils.hamming_distance(s1, s2)
     self.assertEqual(h_dist, 37)