Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > looking for math

Reply
Thread Tools

looking for math

 
 
soldier.coder
Guest
Posts: n/a
 
      02-06-2011
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?

 
Reply With Quote
 
 
 
 
Anton Zeuchert
Guest
Posts: n/a
 
      02-06-2011
How about http://ruby-doc.org/ruby-1.9/classes/Digest.html?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Fabio Cevasco
Guest
Posts: n/a
 
      02-06-2011
[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/di...doc/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 <
http://www.velocityreviews.com/forums/(E-Mail Removed)> 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?
>
>
>


 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      02-06-2011
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/Cryptog..._hash_function

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
Math.min and Math.max for byte / short Philipp Java 9 07-23-2008 12:37 AM
math.h trig functions questions (and some forgotten high school math) Mark Healey C Programming 7 05-22-2006 10:42 AM
Re: Is still math.h the C++ math library ? AciD_X C++ 4 04-01-2004 07:29 PM
Why can I not use: Math a=new Math(); chirs Java 18 03-02-2004 06:00 PM



Advertisments