Question

How can hashing be used to compare the contents of two files without opening them.

How can hashing be used to compare the contents of two files without opening them.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

You can generate the hash of the contents, and then compare the hashes. If the hashes are identical, the files are the same.

In ruby it would look something like this.

md5hashFile1 = Hash(file1)
md5hashFile2 = Hash(file2)

expect(md5hashFile1).to eq(md5hashFile2)

MD5 hash algorithm takes the content and get a hash value out of it. So, if the contents are actuually same the md5 hash will also fetch the same checkSum without opening the file in front of user.

All files are a collection of bytes (values 0-255). If two files MD5 hashes match, both those collections of bytes are extremely likely the exact same (same order, same values).

There's a very small chance that two files can generate the same MD5, which is a 128 bit hash. The probability is:

Probability of just two hashes accidentally colliding is 1/2128 which is 1 in 340 undecillion 282 decillion 366 nonillion 920 octillion 938 septillion 463 sextillion 463 quintillion 374 quadrillion 607 trillion 431 billion 768 million 211 thousand 456.

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
How can hashing be used to compare the contents of two files without opening them.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT