Member-only story
How the SHA-2 (SHA-256) Hashing Algorithm Works
SHA-2 (Secure Hash Algorithm 2) is one of the most popular families of hashing algorithms. In this article, we’ll walk through each step of the SHA-256 algorithm, which belongs to SHA-2, and show how it works with a real example.
What is a hash function?
If you want to know more about hash functions, you can read Wikipedia. But to understand what this is about, let’s remember the three main purposes of a hash function:
- ensure data integrity (invariance) check;
- accept input of any length and output the result of a fixed length;
- change data irreversibly (input cannot be obtained from output).
SHA-2 and SHA-256
SHA-2 is a family of algorithms with the general idea of hashing data. SHA-256 sets additional constants that define the behavior of the SHA-2 algorithm. One of these constants is the output size. “256” and “512” refer to the respective sizes of the output data in bits.
We’ll look at an example of how SHA-256 works.
SHA-256 “hello world”
Step 1. Pre-processing
1. Let’s convert “hello world” to binary:
01101000 01100101…