hashing

Persisting hashlib state

I'd like to create a hashlib instance, update() it, then persist its state in some way. Later, I'd like to recreate the object using this state data, and continue to update() it. Finally, I'd like to get the hexdigest() o the total cumulative run of data. State persistence has to survive across multiple runs. Example: import hashlib m ...

C# creating a fixed size hashtable

I want to be able to create a fixed size hashmap of say 100 buckets, and if I need to store over 100 items then collisions and overwriting will just have to happen. The hashtable class has a IsFixedSize property however it is readonly. Am I thinking about this completely wrongly, or is there a solution to this? ...

What is the BCL equivalent of GetValueElseAdd in PowerCollections

In Wintellect's PowerCollections, there's a GetValueElseAdd which works like this: if ( collection.GetValueElseAdd( key, ref value)) { // just added, value unmodified } Or // factory method only gets called if the key is not present. if ( collection.GetValueElseAdd( key, out value, () => thingFactory.CreateNew())) { // just a...

How do I create an MD5 hash digest from a text file with C#?

Using C#, I want to create an MD5 hash of a text file. How can I accomplish this? Please include code. Many thanks! Update: Thanks to everyone for their help. I've finally settled upon the following code - // Create an MD5 hash digest of a file public string MD5HashFile(string fn) { byte[] hash = MD5.Cr...

How can I recognize slightly modified images?

I have a very large database of jpeg images, about 2 million. I would like to do a fuzzy search for duplicates among those images. Duplicate images are two images that have many (around half) of their pixels with identical values and the rest are off by about +/- 3 in their R/G/B values. The images are identical to the naked eye. It'...

Am I misunderstanding what a hash salt is?

I am working on adding hash digest generating functionality to our code base. I wanted to use a String as a hash salt so that a pre-known key/passphrase could be prepended to whatever it was that needed to be hashed. Am I misunderstanding this concept? ...

How can I create an SHA512 digest string in Java using bouncy castle?

This unit test is failing: public void testDigest() throws NoSuchAlgorithmException { String hashExpected = "150a14ed5bea6cc731cf86c41566ac427a8db48ef1b9fd626664b3bfbb99071fa4c922f33dde38719b8c8354e2b7ab9d77e0e67fc12843920a712e73d558e197"; MessageDigest md = new MessageDigest(); String hashActual = new String(md.digest("...

Why, after using 'CryptSetHashParam', can I no longer add data to my MD5 hash object?

I am trying to use the Microsoft 'Crypt...' functions to generate an MD5 hash key from the data that is added to the hash object. I am also trying to use the 'CryptSetHashParam' to set the hash object to a particular hash value before adding data to it. According to the Microsoft documentation (if I am interpreting it correctly), you s...

How to write a hash function in C?

Hash Tables are said to be the fastest/best way of Storing/Retrieving data. My understanding of a hash table, hashing is as follows (Please correct me if I am wrong or Please add If there is anything more): A Hash Table is nothing but an array (single or multi-dimensional) to store values. Hashing is the process to find the index/loca...

Linear Hashing Implementations

Does anyone know if there is a C# implementation of Linear Hashing? Failing that are there any implementations in any other language where the code is available? ...

Is Forms Authentication Hash machine dependent?

I'm planning to use this piece of code in my Asp.net app string strUserInputtedHashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(tbPassword.Text, "sha1"); if(strUserInputtedHashedPassword == GetUsersHashedPasswordUsingUserName(tbUserName.Text)) { // sign-in successful } else { // sign-in failed } Is the Has...

Shortening/Rehashing UUIDs

Hi, first of all, I want to assure that I'm aware of the fact, that rehashing is a sensible topic. However I'd like to hear some opions of you, what approach you would take here. I'm building a distribured application, where nodes remotely create entities identified by a UUID. Eventually, all entities should be gathered at a dedicated ...

Determine when files in folder change on demand

I am creating an RSS feed on-demand from a folder of images. The feed creation is pretty expensive on large sets of files obviously, so I am caching the feed after first creation but I'd like to know if I need to re-create the feed when someone calls for it. I'm thinking that if I could figure out a way to cheaply create a unique hash ...

How to implement hash function in Java?

Hi, I've used an array as hash table for hashing alogrithm with values: int[] arr={4 , 5 , 64 ,432 }; and keys with consective integers in array as: int keys[]={ 1 , 2 , 3 ,4}; Could anyone please tell me, what would be the good approach in mapping those integers keys with those arrays location? Is the following a short and bette...

A couple of questions about Hash Tables

I've been reading a lot about Hash Tables and how to implement on in C and I think I have almost all the concepts in my head so I can start to code my own, I just have a couple of questions that I have yet to properly understand. As a reference, I've been reading this: http://eternallyconfuzzled.com/jsw_home.aspx 1) As I've read on the...

Storing hashed passwords in MySQL

Hi I'm creating hashed passwords using salted sha1 in PHP. My question is: In MySQL what is the proper character encoding, field type & length to store the result? Is there anything else in MySQL to consider for password security? Finally are SHA256 or SHA512 practical hashing choices? ...

When do hashes collide?

I understand that according to pigeonhole principle, if number of items is greater than number of containers, then at least one container will have more than one item. Does it matter which container will it be? How does this apply to MD5, SHA1, SHA2 hashes? ...

Hashing tomcat passwords

I am trying to use hashing for a test case in tomcat-users.xml. (I plan on implementing a subclass of one of the Realm classes to do the real authentication with auditing, logging, etc.) I ran the command $TOMCAT_HOME/bin/digest.sh -a sha secret and got the result 'secret:e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4'. I pasted this into t...

Hashes of Array in Perl : traversal and deletion

Hi, how can i delete an element from the following hash of arrays; %HoA = ( flintstones => [ {day=>'19'}, {day=>'21'}, {day=>'22'} ], jetsons => [ {day=>'29'}, {day=>'23'}, {day=>'25'} ], simpsons => [ {day=>'26'}, {day=>'33'}, {day=>'27'} ] ); Like how can i delete e.g {day=>'21'} from flintstones and make...

How stupid it is to use an integer value a key for an Hash Table?

Hi, I'll be needing to use Hash Tables with different keys. One as string for the key and another as integer. As for the integer one, how stupid it is to run a hash function on the number to generate a key? I mean, the numbers I'll be using as key for the Hash Table will always be different, there will be no duplicates at all. Isn't e...