243
votes
Accepted
Where do "magic" hashing constants like 0x9e3779b9 and 0x9e3779b1 come from?
0x9e3779b9 is the integral part of the Golden Ratio's fractional part 0.61803398875… (sqrt(5)-1)/2, multiplied by 2^32.
Hence, if φ = (sqrt(5)+1)/2 = 1.61803398875 is the Golden Ratio, the hash ...
73
votes
How can I protect an SQL connection string in a client-side application?
You don't.
You put your SQL Server behind some sort of (probably web) API and use any of the numerous methods for securing an API. Anything which exists on a client's machine is not secure.
41
votes
How to implement float hashing with approximate equality
implement equality testing and hashing for Temperature in a way that compares floats up to an epsilon difference instead of direct equality testing,
Fuzzy equality violates the requirements that Java ...
33
votes
Where do "magic" hashing constants like 0x9e3779b9 and 0x9e3779b1 come from?
The other answers explain the intent behind those magic numbers, which is probably what you wanted to know. However one could say that where "they come from" is from bad programming practices. Magic ...
31
votes
Accepted
How can I protect an SQL connection string in a client-side application?
There are two options I can see:
The "modern" option: As Philip Kendall explains, don't. Do not directly connect to the database from the client. Instead, have a dedicated backend service ...
17
votes
How to implement float hashing with approximate equality
Good Luck
You are not going to be able to achieve that, without being stupid with hashes, or sacrificing the epsilon.
Example:
Assume that each point hashes to its own unique hash value.
As ...
15
votes
If passwords are stored hashed, how would a computer know that your password is similar to the last one if you try resetting your password?
One way to implement this is if you reset password, you are usually asked to enter your old password as well. You can simply just use regular string similarity comparison in that situation because you ...
13
votes
What is an example for a one-way hash function?
It seems you'tre talking about cryptographic hash functions, where it's essential that you cannot easily construct any input that will have a given output - that is what "one-way function" means. Hash ...
12
votes
If passwords are stored hashed, how would a computer know that your password is similar to the last one if you try resetting your password?
The simple answer is that a secure system does not know if they are similar.
But some systems intentionally reduce the security for a specific password in someways to prevent new passwords from being ...
11
votes
Accepted
What are Hash Functions?
A hash function is a function that, in general, takes an arbitrary-size string and returns a fixed-sized number. Thus, it can be seen as compressing lots of information into a small fingerprint. For ...
10
votes
Accepted
(closed) Why do we bother hashing data?
For the same reason you lock your doors when you are gone: It makes it more difficult for someone to steal from you. Additionally, there are steps you can take when "encrypting" data (...
8
votes
Accepted
Why can't Dictionary(TKey, TValue) update it's hashcodes?
Why doesn't the Dictionary class have logic to move an object to the correct bucket when it detects that the object's hashcode has changed?
Just to be sure, we are talking about the hash of the key ...
8
votes
How to implement float hashing with approximate equality
You can model your temperature as an integer under the hood. Temperature has a natural lower bound (-273.15 Celsius). So, double (-273.15 is equal to 0 for your underlying integer). The second element ...
7
votes
What is an example for a one-way hash function?
All hash functions are one-way. Hash functions map a larg(er) (potentially infinite) input space into a small(er) (usually finite) output space.
If you are familiar with the Pigeonhole Principle, ...
7
votes
Accepted
Is there a secure way to check previous passwords purely on the client-side?
Secrets Are Not Shared
Unless they are not secrets
Ironically from a security perspective that delay, is actually a feature.
To a user, for the most part they will get it right, perhaps they will ...
7
votes
If passwords are stored hashed, how would a computer know that your password is similar to the last one if you try resetting your password?
If passwords are stored hashed, how would a computer know that your password is similar to the last one if you try resetting your password? Wouldn't the two passwords be totally different since one is ...
7
votes
(closed) Why do we bother hashing data?
I know it could slow [hackers] down, but you could just look up a decryptor.
Sure. But that's missing the point. For any good encryption algorithm, everyone knows the decryptor. Everyone knows the ...
7
votes
Accepted
What is the benefit of caching a hash value in a string object?
I'm not convinced there is any worthwhile benefit, and the feature comes at an opportunity cost.
It would be wise to run benchmarks against real-world applications written in your language before ...
6
votes
Why can't Dictionary(TKey, TValue) update it's hashcodes?
Short answer: Dictionary can't detect that some hashcode changed. There is no event that it can subscribe to. Getting hashcode is just a call to Object.GetHashCode(). That method is called once when ...
6
votes
What are some disadvantages for a hashmap with timestamp as key?
My first reaction would be about range queries. Like finding the value right after/before a given timestamp.
Looking up a value requires that you have the exact timestamp, if you miss be 1 times the ...
6
votes
hash-like algorithm to identify passwords which are "too similar" to previous ones from history
Similarity hashing and all such related techniques are highly insecure when applied to passwords. Currently, it seems that best practices are:
DO apply password strength metrics
minimum length
check ...
5
votes
Why can't Dictionary(TKey, TValue) update it's hashcodes?
If the hash code of the key can change, then the keys can change, and keys that were different can become equal. And now you have a dictionary with equal values and a serious problem.
5
votes
Why can't Dictionary(TKey, TValue) update it's hashcodes?
Why doesn't the Dictionary class have logic to move an object to the correct bucket when it detects that the object's hashcode has changed?
Because that defeats the object of a dictionary. The whole ...
5
votes
Explanation of how to resolve Hash conflicts in HAMT or hashtables in general
A hashtable is an array of buckets, where the bucket index corresponds to the hash values of the keys (modulo the array length).
As collisions do happen (two different keys mapping to the same bucket)...
5
votes
Where do "magic" hashing constants like 0x9e3779b9 and 0x9e3779b1 come from?
In code dealing with hash tables, I often find the constant 0x9e3779b9 or sometimes 0x9e3779b1
The other answer correctly explained why this value is used. However, if you often find this constant, ...
5
votes
Accepted
Why use strong checksums to detect random errors in a filesystem like btrfs?
A question is which width of xxhash is used?
Due to the birthday paradox the chance of an accidental collision is higher than you might think. For example there's a 50% chance of an accidental ...
5
votes
Accepted
Why is there no Hashmap in C++ like Java?
In short
An interview question like "why isn't there a HashMap in C++" should be immediately answered with "Because there is std::unordered_map".
Some more arguments
According to ...
4
votes
What is an example for a one-way hash function?
Here's a simple example:
A hash of the string "Hello world!" is "Hel". If you're given "Hel", you cannot recreate "Hello world!", and yet it is likely not going to clash with many other strings.
...
4
votes
Where and how to handle user password hashing in Clean Architecture?
Identity management is probably not part of your core problem domain, therefore it has no place among your core business logic. Also, your entities (the center in the Clean Architecture) should not ...
4
votes
A collision-free hash-like function for use in hash tables and other data structures?
You write "Idea #1: use the positional number of a string in the table as its unique ID." but this is not how sequences work. If you want to avoid contention around the sequences, you use sequence ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
hashing × 167algorithms × 36
security × 22
data-structures × 17
java × 13
passwords × 13
c# × 10
encryption × 6
dictionary × 6
javascript × 5
python × 5
c × 5
performance × 5
file-systems × 5
hashtable × 5
design × 4
database × 4
strings × 4
search × 4
map × 4
cryptography × 4
design-patterns × 3
c++ × 3
php × 3
sorting × 3