Questions tagged [hash]

A hash function is any well-defined procedure or mathematical function that converts a large amount of data into a small datum, usually a single integer. For questions about hashtags as used to label content on social media, use hashtag. For questions about URLs and HTML anchors, use fragment-identifier. For questions about Ruby's hash type, use ruby-hash.

A is any well-defined procedure or mathematical function that converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an index to an array. The values returned by a hash function are called hash values, s, hash sums, checksums or simply hashes. A occurs when two unequal datums generate the same hash code with a particular hash function. This can have various negative effects and good hash functions minimize the number of collisions.

For data structures that make use of hash functions and hashcodes, see , , , , and .

A cryptographically strong hash function has two additional features: it is mathematically proven to be irreversible and minimizes collisions. Irreversibility means that the original data cannot be reconstructed from its hash. For questions specifically about cryptographically secure uses of hash functions, use combined with the tag. Contrast with , which must be reversible.

Hash functions are related to (and often confused with) checksums, check digits, fingerprints, randomization functions, and error-correcting codes. Although these concepts overlap to some extent (some hash functions are specifically designed to also serve as checksums), each has its own uses and requirements and is designed and optimized differently.

For questions about hashtags as used to label and navigate content on social media, use . For questions about URLs and HTML anchors, use . For questions about Ruby's hash type, use .

23903 questions
9
votes
3 answers

Ruby - Set Value of nested hash from array of keys

I learned from Access nested hash element specified by an array of keys) that if i have a array array = ['person', 'age'] and I have a nested hash hash = {:person => {:age => 30, :name => 'tom'}} I can get the value of of age by…
seanrclayton
  • 157
  • 1
  • 7
9
votes
3 answers

Can I use part of MD5 hash for data identification?

I use MD5 hash for identifying files with unknown origin. No attacker here, so I don't care that MD5 has been broken and one can intendedly generate collisions. My problem is I need to provide logging so that different problems are diagnosed easier.…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
9
votes
1 answer

Construct Hash in Jekyll/Liquid

I was wondering if is there any way to construct a hash variable in Jekyll/Liquid. Maybe something like this: {% assign x = { foo: 1, bar: 2 } %} {{ x[foo] }} {{ x[bar] }}
Linlin Yan
  • 91
  • 3
9
votes
3 answers

Python hash() can't handle long integer?

I defined a class: class A: ''' hash test class >>> a = A(9, 1196833379, 1, 1773396906) >>> hash(a) -340004569 This is weird, 12544897317L expected. ''' def __init__(self, a, b, c, d): self.a = a self.b…
Xie
  • 154
  • 2
  • 7
9
votes
2 answers

Recursively modify values in a nested hash

Given the following hash structure I would like to walk the structure and make a modification to all of the values with a key of "link": {"page_id":"12345", "link_data":{"message":"test message", "link":"https://www.example.com",…
cgallagher
  • 235
  • 2
  • 10
9
votes
4 answers

How to compare Laravel's hash password using a custom login form?

Can you help me with this? I am building my own login form using Laravel. But I have a problem because I stored my password using Hash method and in my login form I used hash method again to compare. But I found out that the hash value is always…
Jerielle
  • 7,144
  • 29
  • 98
  • 164
9
votes
2 answers

Should I use hash or btree for a foreign key index in postgresql 9.3?

Which index will perform better for foreign keys of type integer in postgresql 9.3? I would assume a hash index, because foreign key comparisson are always made with = Or does a btree compare as fast as a hash when used for JOINS on foreign…
frasen
  • 169
  • 2
  • 6
9
votes
1 answer

Upgrade password hash from md5 to bcrypt

Its been discussed here before, but there seems to be no conclusion. Ideally, don't want to maintain state (upgraded/not upgraded) in the database etc. so, here is what I'm thinking: bcrypt the MD5'd password, and use "username + something else" as…
merlinbeard
  • 218
  • 1
  • 3
  • 14
9
votes
4 answers

creating unordered_set with lambda

How can I make unordered_set with lambda? (I know how to make it with user defined hash struct and operator==) My current code is : #include #include struct Point { float x; float y; Point() : x(0), y(0)…
uchar
  • 2,552
  • 4
  • 29
  • 50
9
votes
2 answers

HashMap UUID or String as key?

HashMap Which is better? I know UUIDs dont use that much memory but what is generally better to use?
ntakouris
  • 898
  • 1
  • 9
  • 22
9
votes
2 answers

How to get hash value in user.config path?

I have installed .NET application. Its config location is %AppData%\[CompanyName]\[ExeName]_Url_[hash]\[version]\user.config. I need to get [hash] value from another application. According with MSDN, user.config path template is [c:\Documents…
user3821449
  • 91
  • 1
  • 2
9
votes
4 answers

Golang md5 Sum() function

package main import ( "crypto/md5" "fmt" ) func main() { hash := md5.New() b := []byte("test") fmt.Printf("%x\n", hash.Sum(b)) hash.Write(b) fmt.Printf("%x\n",…
w00d
  • 5,416
  • 12
  • 53
  • 85
9
votes
5 answers

Hash code as key in keyed collection

As far as I (thought to) know, a Dictionary is implemented as a hashtable, where the hash code is used to identify a bucket, which is then searched for the key. In my opinion, this implies that the hash code of an object remains stable during a…
JohnB
  • 13,315
  • 4
  • 38
  • 65
9
votes
3 answers

Perl: Access a hashref sorted by value

I'm writing a script that'll read through my ftpd logs and generate a hash as follows: $stats = \{ 'user1' => { 'files' => 281, 'size' => '3724251021' }, …
somebody
  • 495
  • 1
  • 7
  • 13
9
votes
5 answers

When do hashes collide?

I understand that according to pigeonhole principle, if number of items is greater than number of containers, then at least one container will have more than one item. Does it matter which container will it be? How does this apply to MD5, SHA1, SHA2…
user963241
  • 6,758
  • 19
  • 65
  • 93
1 2 3
99
100