I need simple hash function that takes two parameters, with the following parameters:
- a,b,c,d are different strings (approximately 30 characters)
- f(a,b) = f(b,a)
- f(a,c) ≠ f(a,d)
- f(c,b) ≠ f(d,b)
I need simple hash function that takes two parameters, with the following parameters:
Sort and concatenate the two parameters (to ensure that f(a,b)
equals f(b,a)
. Since there are only two items to sort the result will be either ab
or ba
.
If the strings have the property that ab
may equal cd
(for example strong
+ hearted
and strongheart
+ ed
) you may want to "salt" the string by prepending it with the length of the first string coded in a fixed number of bytes.
Then apply a string hash on the result. There are numerous examples online.
Note that there is no guarantee that two different strings won't result in the same hash value, but a good hash algorithm will reduce the probability.