SHA1 collision demo / example

New answer as of February 23rd 2017 For more than six years, the SHA1 cryptographic hash function underpinning Internet security has been at death’s door. Now it’s officially dead, thanks to the submission of the first known instance of a fatal exploit known as a “collision.” Previous answer (no longer accurate) There is no known … Read more

c# How to find if two objects are equal

Your current equality method is broken – there are more values than possible hash codes. It’s entirely reasonable (and expected) that you will occasionally have values which are unequal but give the same hash. Equals should check the actual values: public override bool Equals(object obj) { Test test = obj as Test; if (obj == … Read more

How to use SHA1 hashing in C programming

If you have all of your data at once, just use the SHA1 function: // The data to be hashed char data[] = “Hello, world!”; size_t length = strlen(data); unsigned char hash[SHA_DIGEST_LENGTH]; SHA1(data, length, hash); // hash now contains the 20-byte SHA-1 hash If, on the other hand, you only get your data one piece … Read more

How to hash std::string?

For a quick solution involving no external libraries, you can use hash<std::string> to hash strings. It’s defined by including the header files hash_map or unordered_map (or some others too). #include <string> #include <unordered_map> hash<string> hasher; string s = “heyho”; size_t hash = hasher(s); If you decide you want the added security of SHA, you don’t … Read more

Is the hashCode function generated by Eclipse any good?

You can see the implementation of hashCode function in java.util.ArrayList as public int hashCode() { int hashCode = 1; Iterator<E> i = iterator(); while (i.hasNext()) { E obj = i.next(); hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode()); } return hashCode; } It is one such example and your Eclipse generated code follows a … Read more

Do cryptographic hash functions reach each possible values, i.e., are they surjective?

First, let’s point out that SHA-256 does not accept all possible binary strings as input. As defined by FIPS 180-3, SHA-256 accepts as input any sequence of bits of length lower than 2^64 bits (i.e. no more than 18446744073709551615 bits). This is very common; all hash functions are somehow limited in formal input length. One … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)