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
4 answers

Ruby Convert String to Hash

I'm storing configuration data in hashes written in flat files. I want to import the hashes into my Class so that I can invoke corresponding methods. example.rb { :test1 => { :url => 'http://www.google.com' }, :test2 => { { :title =>…
user3063045
  • 2,019
  • 2
  • 22
  • 35
9
votes
5 answers

How to compute the hash code for a stream in the same way as List.hashCode()

I just realized that implementing the following algorithm to compute the hash code for a stream is not possible using Stream.reduce(...). The problem is that the initial seed for the hash code is 1 which is not an identity for the accumulator. The…
Roland
  • 7,525
  • 13
  • 61
  • 124
9
votes
1 answer

What is the reason for _secret_backdoor_key variable in Python HMAC library source code?

When I was browsing Python HMAC module source code today I found out that it contains global variable _secret_backdoor_key. This variable is then checked to interrupt object initialization. The code looks like this # A unique object passed by…
Pawel Miech
  • 7,742
  • 4
  • 36
  • 57
9
votes
1 answer

Hashable enum in Swift

I'd like to have an enum with two cases with a Hashable associated type each conform to Hashable, like so: enum WordOrNumber { case Word(String) case Number(Int) } The first idea I had for hashing was the following: extension WordOrNumber:…
9
votes
2 answers

Fast hash function for `std::vector`

I implemented this solution for getting an hash value from vector: namespace std { template struct hash> { typedef vector argument_type; typedef std::size_t result_type; result_type…
justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
9
votes
5 answers

Create hash using block (Ruby)

Can I create a Ruby Hash from a block? Something like this (although this specifically isn't working): foo = Hash.new do |f| f[:apple] = "red" f[:orange] = "orange" f[:grape] = "purple" end
user94154
  • 16,176
  • 20
  • 77
  • 116
9
votes
3 answers

unordered_map - Hash function has no effect

Why in the following the hash function (which returns constant 0) seems not be taking any effect? Since the hash function is returning constant, I was expecting as output all values to be 3. However, it seems to uniquely map the std::vector values…
rph
  • 901
  • 1
  • 10
  • 26
9
votes
2 answers

Perl DBI fetchall_hashref

Consider the following table: mysql> select * from vCountryStatus; +-------------+------------+------+---------+--------+-----------------+ | CountryName | CountryISO | Code | Status | Symbol | CurrencyName …
emx
  • 1,295
  • 4
  • 17
  • 28
9
votes
4 answers

How to decode with MessageDigest , Base64

I am currently encoding a password. I have to decode the password. Here is the code to encode. I am trying to get the original password compare it. I have researched about MessageDigest that says it is a one-way method. Not sure how to get the…
Perry
  • 101
  • 1
  • 1
  • 4
9
votes
3 answers

Java HashMap detect collision

Is there a way to detect collision in Java Hash-map ? Can any one point out some situation's where lot of collision's can take place. Of-course if you override the hashcode for an object and simply return a constant value collision is sure to…
Emil
  • 13,577
  • 18
  • 69
  • 108
9
votes
1 answer

ASP.NET membership HashAlgorithmType defaults to HMACSHA256, so is password hash keyed?

I have an ASP.NET 4.5 web application that uses a SqlMembershipProvider. During development, someone put passwordFormat="Clear" in the config causing the passwords to be saved in clear text. I want to remove this and enable hashing of passwords, but…
xr280xr
  • 12,621
  • 7
  • 81
  • 125
9
votes
3 answers

How can I sanitize all params coming into a Sinatra app?

In a similar Rails app, I was able to make a recursive Hash-checking function which then runs the Sanitize gem's clean/fragment method to remove any HTML elements from incoming params hash. I used a before filter in the application_controller so…
rcd
  • 1,348
  • 1
  • 14
  • 27
9
votes
1 answer

What hashing algorithm does Windows 10 use to store passwords?

I have recently been taught about hashing in A-Level Computing and wondered if I could write a program to hash passwords using the same algorithm as Windows 10. The reason I want to use the same algorithm as used to store passwords in Windows 10 is…
James Vickery
  • 732
  • 3
  • 10
  • 23
9
votes
1 answer

Are SHA1 hashes distributed uniformly?

I have a string in Python. I calculate the SHA1 hash of that string with hashlib. I convert it to its hexadecimal representation and take the last 16 characters to use as an identifier: hash_str = "foobarbazάλφαβήταγάμμα..." hash_obj =…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
9
votes
1 answer

Comparing SHA256 made with PHP hash() and NodeJS crypto.createHash()

I'm working on making a real-time application for my website in NodeJS, allowing my users to log in with their accounts, etc. However, I am having some issues with the logging in part. When I register/login the users on the main site, I hashed…
Axiom
  • 902
  • 1
  • 10
  • 23