looking for math

Discussion in 'Ruby' started by soldier.coder, Feb 6, 2011.

  1. 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?
     
    soldier.coder, Feb 6, 2011
    #1
    1. Advertising

  2. Anton Zeuchert, Feb 6, 2011
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    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 Cevasco
    =======================
    web: http://www.h3rald.com
    twitter: http://twitter.com/h3rald




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

    > 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?
    >
    >
    >
     
    Fabio Cevasco, Feb 6, 2011
    #3
  4. 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

    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Feb 6, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chirs
    Replies:
    18
    Views:
    786
    Chris Uppal
    Mar 2, 2004
  2. AciD_X
    Replies:
    4
    Views:
    8,128
    Jonathan Turkanis
    Apr 1, 2004
  3. Mark Healey
    Replies:
    7
    Views:
    1,518
    Tim Prince
    May 22, 2006
  4. Philipp
    Replies:
    9
    Views:
    1,148
    Mark Space
    Jul 23, 2008
  5. VK
    Replies:
    15
    Views:
    1,210
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page