Questions tagged [string-hashing]
90 questions
46
votes
2 answers
Simple hash functions
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…

Hardell
- 721
- 2
- 7
- 13
9
votes
3 answers
C++: Suggestions about a hash function for a sequence of strings where the order of the strings is irrelevant
Let's say you have these two sequences of strings
abc cba bc
bc abc cba
I'm trying to create a mapping for such sequences(the sequence is also a string) so that the above two sequences are mapped into the same bucket.
My initial thought would be to…

ksm001
- 3,772
- 10
- 36
- 57
8
votes
4 answers
djb2 Hash Function
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 */
…

Jainish
- 89
- 1
- 1
- 2
7
votes
3 answers
Java hashcode reverse calculation
I am trying to test out how String hashcode works by adding a new character and do the reverse to subtract it out, however it didn't give me the right answer when i did the calculation.
For example
int PRIME = 31;
//this will print 1687846330…

peter
- 8,333
- 17
- 71
- 94
6
votes
2 answers
hashing user password for client / server application
I have an iPhone App communicating with a web server. When starting the App the user must authenticate with a user name and password.
The communication between the App and the web server is secured (HTTPS) but I don't want to send to the web server…

sebastien
- 2,489
- 5
- 26
- 47
6
votes
3 answers
How to use the password_needs_rehash function in PHP 5.5
I have a set of passwords in my database that I had earlier hashed using sha512 and now that I have upgraded my server to PHP 5.5, I would like to use the bcrypt password hashing. So my idea is to have the user's login and then call this…

Ashesh
- 939
- 2
- 11
- 28
5
votes
4 answers
Hash map optimised for lookup
I am looking for some map which has fixed keys (fixed during initialization) and that does faster look-up. It may not support adding/updating elements later. Is there some algorithm which looks the list of keys and formulates a function so that it…

balki
- 26,394
- 30
- 105
- 151
5
votes
1 answer
Rfc2898DeriveBytes how to verify the password which is store in database as hash value
how to verify password which is store in database as hash value
When I verify the password hash with the database value it will never be the same because it generates the random salt.
how to append the salt in order to verify and test.
Below is the…

Kapil
- 1,823
- 6
- 25
- 47
5
votes
5 answers
Hashing Keys in Java
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?

user1785771
- 487
- 2
- 7
- 18
4
votes
2 answers
Hash function to produce a code of 30 chars?
I need to hash a message into a string of 30 chars. What's the best and most secure hash function for this usage?

cfischer
- 24,452
- 37
- 131
- 214
4
votes
2 answers
Laravel replace primary key with hashids for all get
Im using laravel 4.2 and I want to use hashids instead of primary key in urls. Its easy to use with a single record. If I use eager loading I need to loop through all models and replace the primary keys with hash ids.
For example.
For every post I…

rohitnaidu19
- 673
- 5
- 23
4
votes
4 answers
Hashing array of strings in javascript
Just wondering if there is some other way than this.
var hashStringArray = function(array) {
array.sort();
return array.join('|');
};
I don't like sorting much and using that delimiter is not safe either if it's contained in one of the…

FredyC
- 3,999
- 4
- 30
- 38
3
votes
1 answer
python 3 hashlib.sha256().update(newcontent) seems not to overwrite old content
When I try to use the hash function, it seems the update method doesn't overwrite the string:
For example, given a string magazine
hasher = hashlib.sha256() #set the hasher
hasher.update(magazine.encode('utf-8'))
print( int( hasher.hexdigest(), 16…

midawn98
- 401
- 1
- 4
- 8
3
votes
1 answer
How can i use 'set_password' in custom non-admin model?
I want to use hashing field set_password from User model in django.contrib.auth.models and I'm currently using a custom User model for that.
I'm getting the following error: Attribute error: 'User' object has no attribute…

Ankush paul
- 227
- 1
- 3
- 11
3
votes
1 answer
Find a collision string with a given hash function
I have a string anna, where values of chars in the string are a = 1, n = 14 ( You can compute the value of other chars like ( char - 96 ) and hash function which looks like :
int hashCode( string s ) // s = "anna";
{
k = 0;
for ( int i =…

kvway
- 494
- 4
- 16