首页 > 解决方案 > Cryptopals 在计算密钥大小时挑战 6 个不正确的结果

问题描述

我正在处理Cryptopals 挑战,我被困在挑战 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。

尽管我在挑战中遵循了算法,但我可能误解了它。

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

标签: rustcryptography

解决方案


推荐阅读