Skip to main content
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 ...
32f's user avatar
  • 1,246
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.
Philip Kendall's user avatar
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 ...
Sebastian Redl's user avatar
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 ...
isilanes's user avatar
  • 479
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 ...
sleske's user avatar
  • 10.3k
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 ...
Kain0_0's user avatar
  • 16.6k
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 ...
Lie Ryan's user avatar
  • 12.5k
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 ...
Michael Borgwardt's user avatar
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 ...
Kain0_0's user avatar
  • 16.6k
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 ...
amon's user avatar
  • 136k
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 (...
aasukisuki's user avatar
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 ...
dagnelies's user avatar
  • 5,503
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 ...
Alessandro Teruzzi's user avatar
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, ...
Jörg W Mittag's user avatar
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 ...
Kain0_0's user avatar
  • 16.6k
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 ...
Jörg W Mittag's user avatar
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 ...
Telastyn's user avatar
  • 110k
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 ...
casablanca's user avatar
  • 5,004
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 ...
Sergey Kovalev's user avatar
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 ...
ratchet freak's user avatar
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 ...
amon's user avatar
  • 136k
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.
gnasher729's user avatar
  • 49.4k
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 ...
David Arno's user avatar
  • 39.6k
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)...
Ralf Kleberhoff's user avatar
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, ...
juhist's user avatar
  • 2,579
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 ...
davidbak's user avatar
  • 762
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 ...
Christophe's user avatar
  • 82.1k
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. ...
Neil's user avatar
  • 22.9k
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 ...
amon's user avatar
  • 136k
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 ...
JimmyJames's user avatar
  • 30.9k

Only top scored, non community-wiki answers of a minimum length are eligible