DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Process Mining Key Elements
  • What Is Encryption and How Does It Work?
  • The Transformer Algorithm: A Love Story of Data and Attention
  • Two-Pass Huffman in Blocks of 2 Symbols: Golang Implementation

Trending

  • A Guide to Developing Large Language Models Part 1: Pretraining
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Kubeflow: Driving Scalable and Intelligent Machine Learning Systems
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Decoded: Examples of How Hashing Algorithms Work

Decoded: Examples of How Hashing Algorithms Work

If cryptography were a car, then the hashing algorithm would be its engine.

By 
Jake Adley user avatar
Jake Adley
·
Jan. 22, 19 · Presentation
Likes (4)
Comment
Save
Tweet
Share
20.4K Views

Join the DZone community and get the full member experience.

Join For Free

If cryptography was a body, its hashing algorithm would be the heart of it. If cryptography was a car, its hashing algorithm would be its engine. If cryptography was a movie, its hashing algorithm would be the star. If cryptography was the solar system, its hashing algorithm would be the sun. Okay, that’s probably too far, but you’ve got the point, right? Before we get to the what hashing algorithm is, why it’s there, and how it works, it’s important to understand where its nuts and bolts are. Let’s start with hashing.

What Is Hashing?

Let’s try to imagine a hypothetical situation here. Suppose you want to send a message/file to someone and it is absolutely imperative that it reaches its intended recipient in the exact same format. How would you do it? One option is to send it multiple times and verify that it wasn’t tampered with. But what if the message is too long? What if the file measures in gigabytes? It would be utterly absurd, impractical, and, quite frankly, boring to verify every single letter, right? Well, that’s where hashing comes into play.

Using a chosen hash algorithm, data is compressed to a fixed size. Let’s understand this with an example. If we take the sentence, “Donkeys live a long time” and apply the joaat hash algorithm to it, we will get 6e04f289. This value is known as a hash.

Hashes are highly convenient when you want to identify or compare files or databases. Rather than comparing the data in its original form, it’s much easier for computers to compare the hash values. Whether it’s storing passwords, in computer graphics, or in SSL certificates, hashing does it all.

Fundamentally, hashing is defined by two distinct characteristics – irreversibility and uniqueness. Irreversibility points to the fact that once you hash something, there is no way back. Unlike encryption and encoding, you can’t easily de-hash a message/data. Unique, because no two hash values are ever the same for two different pieces of data. If two hashes are found to be the same for two different pieces of data, it’s called a ‘hash collision’ and that algorithm becomes useless.

(Note: We have used joaat hashing algorithm here as it’s short and easy to comprehend. Modern-day algorithms are much more complex and long.)

Hashing Function: the Core of Hashing Algorithm

“Behind every successful man, there is a great woman.” — Groucho Marx

“Behind every successful hash algorithm, there is a great hash function.” – We just made that up.

Let’s put the jokes aside for a moment and concentrate on the crux of the matter. A hash function is a mathematical function that converts an input value into a compressed numerical value – a hash or hash value. Basically, it’s a processing unit that takes in data of arbitrary length and gives you the output of a fixed length – the hash value.

hashing function










The length of the output or the hash depends on the hashing algorithm. Generally speaking, the most popular hashing algorithms or functions have a hash length ranging from 160 to 512 bits.

Now, let’s move on to the part you’ve been waiting for.

What Is a Hashing Algorithm? How Does it Work?

As we discussed, a hash function lies at the heart of a hashing algorithm. But, to get the hash value of a pre-set length, you first need to divide the input data into fixed sized blocks. This is because a hash function takes in data at a fixed-length. These blocks are called ‘data blocks.’ This is demonstrated in the image below.

hashing function structure

The size of the data block(s) differs from one algorithm to another. But for a particular algorithm, it remains the same. For example, SHA-1 takes in the message/data in blocks of 512-bit only. So, if the message is exactly of 512-bit length, the hash function runs only once (80 rounds in case of SHA-1). Similarly, if the message is 1024-bit, it’s divided into two blocks of 512-bit and the hash function is run twice. However, 99 percent of the time, the message won’t be in the multiples of 512-bit. For such cases (almost all cases), a technique called padding is used. Using a padding technique, the entire message is divided into fixed-size data blocks. The hash function is repeated as many times as the number of data blocks. This is how it’s done:

the avalanche effect in hashingAs shown above, the blocks are processed one at a time. The output of the first data block is fed as input along with the second data block. Consequently, the output of the second is fed along with the third block and so on. Thus, we are making the final output the combined value of all the blocks. If you change one bit anywhere in the message, the entire hash value changes. This is called the 'avalanche effect.'

Popular Hashing Algorithms

  • Message Digest (MD) Algorithm
  • Secure Hash Algorithm (SHA)
  • RACE Integrity Primitives Evaluation Message Digest (RIPEMD)
  • Whirlpool
  • RSA
Algorithm Data (computing) Blocks IT

Published at DZone with permission of Jake Adley. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Process Mining Key Elements
  • What Is Encryption and How Does It Work?
  • The Transformer Algorithm: A Love Story of Data and Attention
  • Two-Pass Huffman in Blocks of 2 Symbols: Golang Implementation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!