hash

Creating an id from name and address data. Hash/Digest

My problem: I'm looking for a way to represent a person's name and address as an encoded id. The id should contain only alpha-numeric characters, be collision-proof, and be represented in a smallest number of characters possible. My first thought was to simply use a cryptographic hash function like MD5 or SHA1, but this seems like ove...

What function to use to hash passwords in MySQL?

I have a user table in my mysql database that has a password column. Currently, I use the MD5 algorithm to hash the users' password for storage in the database. Now I like to think that I am a security conscience person. I noticed while reading the MySQL docs that they don't recommend MD5 or the SHA/SHA1 hashing methods, but don't offer ...

Detecting if two images are visually identical

Sometimes two image files may be different on a file level, but a human would consider them perceptively identical. Given that, now suppose you have a huge database of images, and you wish to know if a human would think some image X is present in the database or not. If all images had a perceptive hash / fingerprint, then one could hash ...

RoR: FasterCSV to hash

I'm really struggling with grasping how to effectively use FasterCSV to accomplish what I want. I have a CSV file; say: ID,day,site test,tuesday,cnn.com bozo,friday,fark.com god,monday,xkcd.com test,saturday,whatever.com I what to go through this file and end up with a hash that has a counter for how many times the first column occur...

Is "double hashing" a password less secure than just hashing it once?

Is hashing a password twice before storage any more or less secure than just hashing it once? What I'm talking about is doing this: $hashed_password = md5( md5( plaintext_password ) ); instead of just this: $hashed_password = md5( plaintext_password ); If it is less secure, can you provide a good explanation (or a link to one)? A...

Client Side MD5 Hash with Time Salt

I want to salt a hashed username and password (submitted via http POST) in JS on the client-side with a higher-order time value (< 1 minute resolution) to avoid sending the username and password hash as a constant value that could be used for a log-in attempt via POST fabrication by an unauthorized user (i.e. a sniffer). This will impos...

How can I combine hashes in Perl?

What is the best way to combine both hashes into %hash1? I always know that %hash2 and %hash1 always have unique keys. I would also prefer a single line of code if possible. $hash1{'1'} = 'red'; $hash1{'2'} = 'blue'; $hash2{'3'} = 'green'; $hash2{'4'} = 'yellow'; ...

Which is faster, Hash lookup or Binary search?

When given a static set of objects (static in the sense that once loaded it seldom if ever changes) into which repeated concurrent lookups are needed with optimal performance, which is better, a HashMap or an array with a binary search using some custom comparator? Is the answer a function of object or struct type? Hash and/or Equal fu...

How to sort not simple hash (hash of hashes)

Hi all! I have a Hash like this { 55 => {:value=>61, :rating=>-147}, 89 => {:value=>72, :rating=>-175}, 78 => {:value=>64, :rating=>-155}, 84 => {:value=>90, :rating=>-220}, 95 => {:value=>39, :rating=>-92}, 46 => {:value=>97, :rating=>-237}, 52 => {:value=>73, :rating=>-177}, 64 => {:value=>69, :rating=>-167}, 86 => {:v...

How can I write out or read in a Perl hash of arrays?

I have a program in Perl I'm working on where I would need multiple keys, and a way of giving each key multiple values and follow that by being able to both read them in and write them out to an external file depending on if the key matches what the person enters into standard input. I've looked across several sites and have found inform...

How do I replace the values of a hash in an external file?

For my program, I'm attempting to replace the value of a specific hash in an external file with a newly created value. The external file has the value tab-delimited from the key, and I had read the hash in from the external file. I've been looking around online, and this is the closest way I could figure out how to do it, yet it doesn't ...

Comparing existing data entries in Java

I have a HashMap relating Keys to Strings, and I need to compare some of the Strings against each other. However, some of the Strings may or may not be in the HashMap. Example: Let's say I have 4 Strings that I plan to compare to each other if possible, but only 3 of them end up in the HashMap. How can I compare the Strings that are p...

How can I sort a hash's keys naturally?

I have a Perl hash whose keys start with, or are, numbers. If I use, foreach my $key (sort keys %hash) { print $hash{$key} . "\n"; } the list might come out as, 0 0001 1000 203 23 Instead of 0 0001 23 203 1000 ...

Fastest Hash Algorithm for Text Data

I'm trying to choose a hash algorithm for comparing about max 20 different text data. Which hash is better for these requirements? Less CPU Consumption Small footprint (<=32 bytes) Collision is not a big deal Can be generated from .NET Framework 2 (shouldn't be a 3rd party library) I'm using hash for less memory footprint and compa...

Good hash algorithm for list of (memory) addresses

I have a list of (64-bit) addresses that represent a stack frame, and I want to hash these to a single 64-bit number to help identify those that have been seen before. There are at most 128 addresses. My current algorithm calculates the hash by iterating through the list, xor'ing each address into the hash and rotating the hash by 11 b...

Which hash method do you use (MD5, SHA1, other?)

This Wikipedia page has an extensive list of hashing methods As you can see, both MD5 and Sha1 have been broken (in Cryptography, "broken" means there's an attack less complex than the brute force attack. In other words, if you need 1 million year to find a collision instead of one billion year using brute force, the algorithm is consid...

How to test a hash function?

Is there a way to test the quality of a hash function? I want to have a good spread when used in the hash table, and it would be great if this is verifyable in a unit test. EDIT: For clarification, my problem was that I have used long values in Java in such a way that the first 32 bit encoded an ID and the second 32 bit encoded another ...

htdigest file format

Hi all, I'm trying to write some code to work with an htdigest password file. The documentation I can find seems to claim that the format of that file is: user:realm:MD5(user:realm:pass) If that is the case, then why doesn't this work for me? I created a file with the command line htdigest thus: htdigest -c test b a When prompted ...

How do I call a constructor on a generic type within a function of a base type without its own constructor?

I thought a great way to test my understanding of generic functions would be to create a function that would spit out a hex representation of a hash using one of the classes that inherits from HashAlgorithm. Since all of the HashAlgorithm classes offer ComputeHash, I thought this would be simple. When I construct such a function. though,...

Are quotes around hash keys a good practice in Perl?

Is it a good idea to quote keys when using a hash in Perl? I am working on an extremely large legacy Perl code base and trying to adopt a lot of the best practices suggested by Damian Conway in Perl Best Practices. I know that best practices are always a touchy subject with programmers, but hopefully I can get some good answers on this...