Kotlin
Java

Hashing
Kotlin

Created By: Geoffrey Challen
/ Updated: 2021-11-15

Welcome back! This lesson explores hashing, a mysterious and yet incredibly useful idea that is even included directly in our programming language!

Today's lesson covers some material that is both extremely cool and very useful for real-world programming. So let's get started! Up first—the mysterious and useful power of hashing...

What is Hashing?

Wikipedia defines a hash function:

A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes.

Let's unpack that definition together...

Review the Wikipedia definition. This explanation should be language agnostic!

Kotlin's hashCode

Hashing turns out to be so useful that a hash function is one of the built-in methods that every Kotlin object provides. Let's see how that works, and how to develop hash codes for our own classes:

How Are Hashes Used?

Are hash functions useful? Yes! Extremely! And, they are also very widely used! Let's go through a few examples.

Download Verification

Hash functions are commonly used to verify downloaded files. Let's see that in action.

Provide some examples of how hashes are used to verify downloads. This explanation should be language agnostic!

Content Fingerprinting

Download verification is one example of an application of hash functions known as content fingerprinting. Let's look at another: Git!

Look at a Git repository together and point out the hashes. This explanation should be language agnostic!

Proof of Work

Hash functions also appear in another perhaps-unexpected place: Bitcoin mining! Let's explore the fundamental concept of proof of work that is used to add blocks to the blockchain:

Hash Collisions

If a hash function produces the same output for two different inputs, this is known as a collision. Whether or not a hash collision is a problem depends a lot on the application. But, it turns out that hash collisions are much more common than we might imagine! Let's see why.

Describe the birthday paradox. This explanation should be language agnostic!

Show how to complete the homework problem above. Feel free to cover multiple approaches!

Solution Walkthrough

Show how to complete the homework problem above. Feel free to cover multiple approaches!

Solution Walkthrough