Hashing and the SHA-256 Algorithm: The Mathematical Seal of Immutability



Hashing and SHA-256 Algorithm

Let's now examine how Hashing (SHA-256)—the primary "mathematical lock" applied to ensure data cannot be deleted or altered on a blockchain—actually works.

What is Hashing (SHA-256)?

Simply put, Hashing is converting data of any arbitrary size (a word, an article, or even an entire movie) into a unique 64-character alphanumeric code. Even tiny data like a single dot "." produces a 64-character output.

The Bitcoin network uses SHA-256 (Secure Hash Algorithm 256-bit). Hashing possesses 3 distinctive properties:

  • Deterministic: No matter how many times you hash the exact same input, you will receive the exact same hash code.
  • Irreversible: You cannot look at the code (Hash) and reverse-engineer what the original data was. (This is like blending fruits into juice; you cannot look at the juice and reconstitute the original fruits).
  • Avalanche Effect: If you alter even a single dot or comma in the original data, the resulting Hash code changes entirely.

Immutable Ledger: Why Can't Data Be Changed?

In a blockchain, blocks are linked to one another through these Hashes. Every block stores the Hash of its own data as well as the Hash of the previous block (Previous Hash). Now imagine a malicious actor attempts to alter data in a block in the middle:

  • The thief changes "10 BTC" to "5 BTC" inside a block.
  • Instantaneously, that block's Hash code changes completely.
  • Consequently, it no longer matches the "Previous Hash" stored in the subsequent block.
  • As a result, every single block following that block becomes Invalid.

For the thief to correct this, they would have to re-solve the mathematical puzzles (Proof of Work) for every block from that point forward. That would require computational power exceeding that of the entire network combined—a practically impossible feat.

Now it should be clear to you:

  • Decentralization නිසා පාලකයෙක් නැහැ.
  • P2P නිසා හැමෝම අතර දත්ත බෙදෙනවා.
  • Hashing නිසා දත්ත වෙනස් කරන්න බැහැ.

When these three elements come together, the Blockchain Foundation is formed. Does that mean the Blockchain Foundation sub-topic ends here? No; if you read this carefully from the beginning, a few more questions must have arisen in your mind.

💡 Note

"Immutable Ledger: The Power of SHA-256.
A blockchain is immutable because of its mathematical bonding. According to the SHA-256 algorithm, even the slightest alteration to data changes its entire Hash code. Because each block carries within it the Hash code of the block preceding it, altering even a single piece of data breaks the entire chain. Consequently, blockchain represents the most secure data repository in the world, whose history cannot be rewritten."

🤔 So who created SHA-256? Was it Satoshi? And does hashing apply only to transaction data?

Who created SHA-256, was it Satoshi?

No, Satoshi Nakamoto did not create SHA-256. It was designed by the US NSA (National Security Agency) in 2001. What Satoshi did was adopt this existing, globally vetted SHA-256 technology as the "security lock" for the Bitcoin system. In other words, Satoshi didn't reinvent the wheel; he took the best wheel available and built a super-vehicle (Bitcoin).

Does Hashing apply only to Transaction Data?

No. Everything inside a block undergoes Hashing. A block's Hash is composed by aggregating all these elements together:

  • Transactions : Details of all transactions (often gathered into a single bundle via a Merkle Tree).
  • Timestamp : The time at which the block was created.
  • Previous Hash : The Hash of the previous block (this is what forms the Chain).
  • Nonce : The "secret number" that Miners vary. This is critical in Proof of Work.

Here is where the magic lies: Because the Previous Hash is included when computing a Block's Hash, one block becomes mathematically locked to the next. Suppose you change a tiny piece of data in Block 2 of a 10-block Chain:

  • Block 2's Hash changes completely.
  • Then the "Previous Hash" written inside Block 3 (which was the old Block 2's hash) no longer matches the new Block 2's Hash.
  • Then Block 3's Hash also changes.
  • In this domino fashion, the entire Chain breaks from 3, 4, 5 all the way to Block 10.

Because of this, to alter the history of a blockchain, you would have to recompute every block from that block forward. Even combining the power of all the world's supercomputers would be insufficient.

🤔 Is SHA-256 some kind of software? Why did the US NSA create it?

Is SHA-256 a software?

No, SHA-256 is not software. It is a mathematical algorithm. The easiest way to understand this is using a culinary "Recipe" analogy. A recipe is simply a set of instructions (an Algorithm). Anyone anywhere can prepare food using that recipe.

SHA-256 is just like that. It contains a series of steps to convert an input into a 64-character code. Anyone can execute this SHA-256 formula using their preferred programming language (Python, C++, Java, etc.).

Why did the US NSA build this?

The NSA (National Security Agency) is a powerful intelligence and security agency in the United States. They design cryptographic methods primarily for two reasons:

  • Government Data Protection: To "Encrypt" highly classified government and military information so enemies cannot access it.
  • Preventing Data Tampering (Data Integrity): To verify whether a dispatched letter or message was altered en route (using Hashing).

The NSA published SHA-256 (part of the SHA-2 family) in 2001 to provide a standard for cybersecurity systems worldwide.

Why did Satoshi Nakamoto choose this exact one?

When designing Bitcoin, Satoshi wanted a robust technology that could never be cracked. Even though the NSA developed it, the world's greatest mathematicians examined it and verified its safety. Due to its open standard nature, anyone had permission to use it. Even today, banking systems and HTTPS (the padlock on web browsers) are protected by technologies like SHA-256. The fact that the NSA created it does not allow them to control the Bitcoin network, because it is a mathematical principle, not something running on a proprietary server controlled by them.

🤔 If SHA-256 is open to everyone, why can't an adversary decrypt what was encrypted with it?

To understand this, we must recognize the fundamental difference between Hashing and Encryption. Many people think both are the same, but they operate entirely differently.

Hashing is a One-Way Street (Irreversible)

SHA-256 is not an Encryption method; it is a Hashing method. In Encryption, data is locked and can later be unlocked (Decrypted) using a key. In Hashing, the data is essentially destroyed and replaced by a brand new fingerprint. Knowing the SHA-256 formula does not allow you to reverse it to recover the original data.

Example: You put an apple into a blender and make juice (the Hash). The whole world knows the recipe for apple juice. But does knowing the recipe allow anyone to turn the apple juice back into an apple? No.

Why Can't an Adversary Crack It? (The Brute Force Problem)

Even if an adversary has the SHA-256 formula, their only way to find the original data corresponding to a specific Hash is through "Brute Force" (hashing every possible word in the universe one by one to see if it matches).

The number of possible combinations in a SHA-256 code is 2256 (115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,936 — a 78-digit number).

This number is so colossal that it exceeds the number of sand grains on the entire Earth. Even if all the supercomputers on Earth were marshaled to compute this, it would take billions of years. That is why it is called Unbreakable.

How Does the Adversary Read the Data Then?

The adversary cannot read the data. That is the security of a blockchain. On a blockchain, SHA-256 is used not to conceal data, but to guarantee that data has not been altered. If someone alters the data, the Hash changes. The fact that SHA-256 is open does not allow an adversary to invent alternative data that yields that exact same Hash without changing the original data.

💡 Note

"The Mathematical Fortress: Why SHA-256 is Unbreakable.
The unique power of SHA-256 is that it is a 'One-way function.' While a Hash can be generated from any data, deducing the original data from the Hash is mathematically infeasible. With its massive search space of 2256 combinations, no supercomputer can crack it via 'Brute Force.' Thus, even though an agency like the NSA created it, its governance belongs to mathematical laws, ensuring it remains permanently open and secure."

🤔 Then how does the recipient of encrypted information decrypt it to see what was sent?

I explained that data cannot be "Decrypted" using SHA-256 (Hashing). So how does one send a confidential message?

This is where Asymmetric Cryptography (Private & Public Keys) and Encryption come into play. Imagine you want to send me a secret message. Here is how it happens:

Encryption (Locking):

You "Encrypt" your message using my Public Key. Now that message turns into unreadable gibberish (Ciphertext).

Decryption (Unlocking):

Now that encrypted message travels across the Internet to me. Anyone can intercept it along the way, but they cannot read it. It can only be read (Decrypted) using the sole key in the world that fits: my Private Key.

How are both used in Blockchain?

In a blockchain, Hashing and Encryption are both used for two distinct purposes:

Hashing (SHA-256):

  • What it does: Creates a "Fingerprint" of data.
  • Why it is used: To ensure data has not been altered (Integrity).

Asymmetric Encryption:

  • What it does: Locks data so only the intended recipient can read it.
  • Why it is used: To establish ownership and confidentiality of transactions (Security).

Hashing is like sealing an envelope. If the seal is broken, everyone knows someone tampered with it (though seeing the seal doesn't reveal the contents). Encryption is like writing the contents inside the letter in a secret cipher that only the recipient understands.

💡 Note

"Integrity vs Privacy: How Cryptography Balances Both.
The security of a blockchain network consists of two layers. Hashing maintains the correctness (Integrity) of all data across the network, while Asymmetric Encryption confirms the confidentiality and ownership of individual transactions. The combination of these two technologies makes a blockchain simultaneously transparent and exceptionally secure."

Comments

Comments