rust - 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。
尽管我在挑战中遵循了算法,但我可能误解了它。
我不知道为什么它不起作用,我已经阅读了很多关于如何解决这个挑战的文章,但没有一篇文章遵循挑战中的算法。
解决方案
推荐阅读
- react-native - 视图在 React Native iOS 上无缘无故地颤抖
- c++ - 使用 XOR 逻辑查找丢失的数字
- embedded - 如何在不更新整个固件的情况下使嵌入式系统可配置
- apollo-client - Apollo-client 状态管理缓存在保存和删除操作后不会自动更新
- kotlin - micronaut 数据和复合键映射
- c++ - 如何让两个进程完成一个任务,谁先完成任务,再终止另一个
- r - 使用相同的名称和数字后缀动态重命名所有列
- python - 使用循环创建数组(Python)
- python - Python骰子模拟器,为什么它不停地运行?
- networking - BitTorrent 协议的 RFC 是什么?