hash

Can one construct a "good" hash function using CRC32C as a base.

Given that SSE 4.2 (Intel Core i7 & i5 parts) includes a CRC32 instruction, it seems reasonable to investigate whether one could build a faster general-purpose hash function. According to this only 16 bits of a CRC32 are evenly distributed. So what other transformation would one apply to overcome that? Update How about this? Only 16 ...

Strange ruby behavior when using Hash.new([])

Consider this code: h=Hash.new(0) #new hash pairs will by default have 0 as values h[1]+=1 # {1=>1} h[2]+=2 # {2=>2} that's all fine, but: h=Hash.new([]) #empty array as default value h[1]<<=1 #{1=>[1]} - OK h[2]<<=2 #{1=>[1,2], 2=>[1,2]} # why ?? At this point I expect the hash to be: {1=>[1], 2=>[2]} But something goes wrong....

Operations on Python hashes

I've got a rather strange problem. For a Distributed Hash Table I need to be able to do some simple math operations on MD5 hashes. These include a sum (numeric sum represented by the hash) and a modulo operation. Now I'm wondering what the best way to implement these operations is. I'm using hashlib to calculate the hashes, but since the...

Best way to get the values of a hash ordered by their respective keys? (Ruby)

Here's what I'm doing atm: test = { 'd' => 20, 'b' => 40, 'c' => 30, 'a' => 50, 'e' => 10 } f = [] test.to_a.sort.each do |e| f << e[1] end puts f.join(' ') Outputs: 50 40 30 20 10 Is there a more efficient/concise/better way to do this? And before someone says so, no, I can't use an array. :p EDIT Sorry, posted the w...

Split Entire Hash Range Into n Equal Ranges

Hello. I am looking to take a hash range (md5 or sha1) and split it into n equal ranges. For example, if m (num nodes) = 5, the entire hash range would be split by 5 so that there would be a uniform distribution of key ranges. I would like n=1 (node 1) to be from the beginning of the hash range to 1/5, 2 from 1/5 to 2/5, etc all the wa...

Speed of QHash lookups using QStrings as keys.

I need to draw a dynamic overlay on a QImage. The component parts of the overlay are defined in XML and parsed out to a QHash<QString, QPicture> where the QString is the name (such as "crosshairs") and the QPicture is the resolution independent drawing. I then draw components of the overlay as they are needed at a position determined dur...

Hashing a python function to regenerate output when the function is modified

I have a python function that has a deterministic result. It takes a long time to run and generates a large output: def time_consuming_function(): # lots_of_computing_time to come up with the_result return the_result I modify time_consuming_function from time to time, but I would like to avoid having it run again while it's un...

What hash algorithms are parallelizable? Optimizing the hashing of large files utilizing on multi-core CPUs.

I'm interested in optimizing the hashing of some large files (optimizing wall clock time). The I/O has been optimized well enough already and the I/O device (local SSD) is only tapped at about 25% of capacity, while one of the CPU cores is completely maxed-out. I have more cores available, and in the future will likely have even more...

How can it be impossible to "decrypt" an MD5 hash?

I was reading a question about MD5, and it made me remember something that boggles me. Very simple question, and I'm sorry if it's not a good one. I just can't understand how you convert something to one thing using some algorithm, and there being no way to convert it back using the algorithm in reverse. So how is this possible? Also, ...

The algorithm used to generate recommendations in Google News?

Hi everyone. I'm study recommendation engines, and I went through the paper that defines how Google News generates recommendations to users for news items which might be of their interest, based on collaborative filtering. One interesting technique that they mention is Minhashing. I went through what it does, but I'm pretty sure that w...

Is calculating an MD5 hash less CPU intensive than SHA-1 or SHA-2?

Is calculating an MD5 hash less CPU intensive than SHA-1 or SHA-2 on "standard" laptop x86 hardware? I'm interested in general information, not specific to a certain chip. UPDATE: In my case, I'm interested in calculating the hash of a file. If file-size matters, let's assume its 300K. ...

Is there a simple way to validate a hash of hash element exists and is defined?

I need to validate a Perl hash of hash element such as $Table{$key1}{$key2} to exist and be defined. Here is what I do. (I have no idea $key1 even exists) if ((defined $Table{$key1}) && (exists $Table{$key1}) && (defined $Table{$key1}{$key2}) && (exists $Table{$key1}{$key2})) { #do whatever } Is there an easier and cleaner w...

Sorting a 2-D hash in reverse order

I have a 2-d hash.I need to sort each sub-hash by value in descending order. hsh={"a"=>{0=>1, 1=>2}} output= {"a"=>{1=>2,0=>1}} Thanks & Cheers ! ...

Spring Security DB Authentication w/Hibernate and hashed passwords?

I'm trying to set up spring security 3 to authenticate users against my hibernate 3 database. I'm storing only sha1 hashes of the passwords in the database (not plaintext). I've looked at this and this, which tell me to implement my own UserDetailsService. Unfortunately, the UserDetails that loadUserByUsername spits out seem to need the...

md5 hash for file without File Attributes

Using the following code to compute MD5 hashs of files: Private _MD5Hash As String Dim _BinaryData As Byte() = New Byte(FileUpload1.PostedFile.InputStream.Length) {} FileUpload1.PostedFile.InputStream.Read(_BinaryData, 0, _BinaryData.Length) Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider Dim md5hash() As Byte...

Take most significant 8 bytes of the MD5 hash of a string as a long (in Ruby)

Hey Friends, I'm trying to implement a java "hash" function in ruby. Here's the java side: import java.nio.charset.Charset; import java.security.MessageDigest; /** * @return most significant 8 bytes of the MD5 hash of the string, as a long */ protected long hash(String value) { byte[] md5hash; md5hash = md5Digest.digest(value.g...

What is a best practice of writing hash function in java?

Hi. I'm wondering what is the best practice for writing #hashCode() method in java. Good description can be found here. Is it that good? ...

Is sending a hashed password over the wire a security hole?

I've come across a system that is in use by a company that we are considering partnering with on a medium-sized (for us, not them) project. They have a web service that we will need to integrate with. My current understanding of proper username/password management is that the username may be stored as plaintext in the database. Every u...

Comparing lists of field-hashes with equivalent AR-objects.

I have a list of hashes, as such: incoming_links = [ {:title => 'blah1', :url => "http://blah.com/post/1"}, {:title => 'blah2', :url => "http://blah.com/post/2"}, {:title => 'blah3', :url => "http://blah.com/post/3"}] And an ActiveRecord model which has fields in the database with some matching rows, say: Link.all => [<Link#2 @ti...

How do I access a value of a nested Perl hash?

I am new to Perl and I have a problem that's very simple but I cannot find the answer when consulting my Perl book. When printing the result of Dumper($request); I get the following result: $VAR1 = bless( { '_protocol' => 'HTTP/1.1', '_content' => '', '_uri' => bless( do{\(my $o = 'http://myaw...