gpt4 book ai didi

string - 为字符串生成校验和

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:44:04 26 4
gpt4 key购买 nike

我想为字符串/数据生成校验和

1. The same data should produce the same Checksum
2. Two different data strings can't product same checksum. Random collision of 0.1% can be negligible
3. No encryption/decryption of data
4. Checksum length need not be too huge and contains letters and characters.
5. Must be too fast and efficient. Imagine generating checksum(s) for 100 Mb of text data should be in less than 5mins. Generating 1000 checksums for less than 1 KB of each segment data should be in less than 10 seconds.

非常感谢任何算法或实现引用和建议。

最佳答案

您可以编写自定义哈希函数:(c++)

long long int hash(String s){
long long k = 7;
for(int i = 0; i < s.length(); i++){
k *= 23;
k += s[i];
k *= 13;
k %= 1000000009;
}
return k;
}

这应该会给你一个很好的(对于大多数样本来说是无冲突的)哈希值。

关于string - 为字符串生成校验和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34153765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com