Looking for math

I’m looking for code that will do some operation on a file and give me
a number that is unique to that file. if I happen to come across same
file somewhere else and the contents are the same, the same number
should be produced.

First what is that called, and anyplace i can see code that does that?

How about http://ruby-doc.org/ruby-1.9/classes/Digest.html?

Perhaps you mean creating checksums or MD5 digests?

The code is simple, assume there’s a “README.textile” file in the
current
directory; just launch IRB and do the following:


ruby-1.9.2-p136 :001 > require “digest”
=> true
ruby-1.9.2-p136 :002 > Digest::MD5.file(“README.textile”).to_s
=> “fd4964756811f1590cc13efb7ac7895a”


For more information, see the Digest library:
http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html

Hope it helps,

Fabio C.

web: http://www.h3rald.com
twitter: http://twitter.com/h3rald

On Sun, Feb 6, 2011 at 6:30 PM, soldier.coder <

soldier.coder wrote in post #979906:

I’m looking for code that will do some operation on a file and give me
a number that is unique to that file. if I happen to come across same
file somewhere else and the contents are the same, the same number
should be produced.

First what is that called

It’s called a “cryptographic hash”.
http://en.wikipedia.org/wiki/Cryptographic_hash_function

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs