开发者

File hash: Does it change for same content but in different order?

Let's say there is a file called myfile.txt with the following contents:

开发者_如何学编程

one two three

Another file called yourfile.txt with following contents:

two three one

Will the SHA-1 hash be the same for both of these files, because the content are same but in different order?


No, it'll be different. Most good general purpose hashing algorithms take order into account. About the only commonly used hash functions that don't are simple checksums.


No, it will be different. Hashes typically work iteratively over a series of bytes.

Of course, you could just try it ;)


Depends on the hash algorithm. I can create one right now that returns two equal hashes for both files.

But since you specifically asked about SHA-1 then yes, they will be completely different.

    SHA1("one two three") = a10600b129253b1aaaa860778bef2043ee40c715
    SHA1("two three one") = 5b836799b259835e762c93964a68b958eb19461a


'Cryptographic' hashes are designed to detect changes like transpositions, otherwise someone could take an electronic payment message and change the $1900.00 amount to $9100.00 without detection (by the hash anyway), which would kind of defeat the purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜