This is the first day of my participation in the Gwen Challenge in November. Check out the details: the last Gwen Challenge in 2021

Hash function

A Hash is a Hash algorithm that transforms an input of any length (also known as a pre-mapped pre-image) into a fixed-length output, which is a Hash value. This transformation is a compression mapping, that is, the space of hash values is usually much smaller than the space of input, and different inputs may be hashed into the same output, so it is impossible to determine a unique input value from the hash value. Simply put, it is a function that compresses a message of any length into a message digest of a fixed length.

Murmur hash

The Murmur hash is an unencrypted hash function suitable for general hash – based look-up. It was created in 2008 by Austin Appleby and hosted on Github as a test suite called “SMHasher”. It also exists in many variations, all of which have been publicized. The name comes from two basic operations, multiplication (MU) and rotation (R), used in its internal loop. Unlike cryptographic hash functions, it is not specifically designed to be difficult to reverse by an adversary and is therefore not suitable for cryptographic purposes.

Murmur hash 3

The 2018 version is Murmur hash 3, which produces a 32-bit or 128-bit hash value. With 128 bits, the x86 and X64 versions do not generate the same value because the algorithms are optimized for their respective platforms.

java

Start by adding com.google.guava import dependencies to your project’s POM.xml file

		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>20.0</version>
		</dependency>
Copy the code

Then use Hashing.murmur3_128().newhasher () to create a newHasher object, pass in the hash string inputStr, set char to UTF-8, and convert hash() to a string on the call. You can generate a 128-bit hash.

      Hashing.murmur3_128().newHasher().putString(inputStr, StandardCharsets.UTF_8).hash().toString();
Copy the code

C # call System. Data. HashFunction MurmurHash

Added in the nuget System. Data. HashFunction. MurmurHash references

Call System. Data. HashFunction. MurmurHash. MurmurHash3Factory. The Instance. The Create Create a hash object, and introduced to hashConfig hashConfig set 128, MurmurHash3.Com puteHash() then passes in an array of string bytes to hash, and finally calls the AsHexString method to generate a 128-bit hash string. Don’t use the toString ()

            var bytes = Encoding.UTF8.GetBytes(inputStr);
            var hashConfig = new System.Data.HashFunction.MurmurHash.MurmurHash3Config();
            hashConfig.Seed = 0;
            hashConfig.HashSizeInBits = 128;
            var murmurHash3 = System.Data.HashFunction.MurmurHash.MurmurHash3Factory.Instance.Create(hashConfig);
            var hashString = murmurHash3.ComputeHash(bytes).AsHexString();
Copy the code