string-hashing

Hashing Keys in Java

落爺英雄遲暮 提交于 2019-12-04 08:03:29
In java, when I use a String as a key for Hashmap I get a little different result than when I use the string hashcode as a key in the HashMap. Any insight? when I use the string hashcode as a key in the HashMap. You mustn't use the hash code itself as the key. Hash codes aren't intended to be unique - it's entirely permitted for two non-equal values to have the same hash code. You should use the string itself as a key. The map will then compare hash codes first (to narrow down the candidate matches quickly) and then compare with equals for genuine string equality. Of course, that's assuming

BCryptHelper.CheckPassword always returns false

巧了我就是萌 提交于 2019-12-02 03:19:27
I'm implementing password hashing using BCrypt, which should be pretty straight forward to use. However when the password is checked against the hashed password using BCryptHelper.CheckPassword(Password, hashedDBPassword) this always return false. Here is my hasher class: public static class BCryptHasher { public static string EncryptPassword(string password) { var passwordToHash = password; var hashedPassword = BCryptHelper.HashPassword(passwordToHash, BCryptHelper.GenerateSalt(6)); return hashedPassword; } public static bool CheckPasswordMatch(string userPassword, string hashedDBPassword) {

Simple hash functions

你。 提交于 2019-11-29 19:52:28
I'm trying to write a C program that uses a hash table to store different words and I could use some help. Firstly, I create a hash table with the size of a prime number which is closest to the number of the words I have to store, and then I use a hash function to find an address for each word. I started with the simplest function, adding the letters together, which ended up with 88% collision. Then I started experimenting with the function and found out that whatever I change it to, the collisions don't get lower than 35%. Right now I'm using unsigned int stringToHash(char *word, unsigned int

djb2 Hash Function

落花浮王杯 提交于 2019-11-29 04:35:16
I am using the djb2 algorithm to generate the hash key for a string which is as follows hash(unsigned char *str) { unsigned long hash = 5381; int c; while (c = *str++) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ return hash; } Now with every loop there is a multiplication with two big numbers, After some time with the 4th of 5th character of the string there is a overflow as the hash value becomes huge What is the correct way to refactor so that the hash value does not overflow and the hashing also happens correctly Hash calculations often overflow. That's generally not a problem at

Simple hash functions

大城市里の小女人 提交于 2019-11-28 15:39:15
问题 I'm trying to write a C program that uses a hash table to store different words and I could use some help. Firstly, I create a hash table with the size of a prime number which is closest to the number of the words I have to store, and then I use a hash function to find an address for each word. I started with the simplest function, adding the letters together, which ended up with 88% collision. Then I started experimenting with the function and found out that whatever I change it to, the