密码学家在计算密钥大小时会挑战6个错误的结果

时间:2019-01-22 17:23:56

标签: rust cryptography

我正在研究Cryptopals challenges,但遇到了挑战6。我编写了以下Rust代码来计算挑战中指定的密钥大小,并且得到了奇怪的结果。

fn get_keysizes(mut ciphertext: Vec<u8>) -> Vec<(usize, u64)> {
    let mut sizelist: Vec<(usize, u64)> = Vec::new();

    for keysize in 2..41 {
        let blocks: Vec<&[u8]> = ciphertext.chunks(keysize).collect();
        sizelist.push((keysize, get_hamming_distance(blocks[0], blocks[1]) / keysize as u64));
    }
    sizelist.sort_by(|x, y| x.1.cmp(&y.1));
    println!("{:?}", sizelist);
    sizelist
}

我使用For each KEYSIZE, take the first KEYSIZE worth of bytes, and the second KEYSIZE worth of bytes, and find the edit distance between them. Normalize this result by dividing by KEYSIZE.作为密钥,通过重复密钥XOR对字符串the cryptopals crypto challenges进行了加密,并将密文传递到我的函数中,并计算出密钥长度为3。

即使我在挑战中遵循了算法,也可能会误解它。

我不知道为什么它不起作用,我读了很多关于如何解决这个挑战的文章,但是没有一篇文章遵循该挑战中的算法。

0 个答案:

没有答案