# Encryption

Encryption in the blockchain refers to the process of converting data into a secure and unreadable format to protect it from unauthorized access or tampering. It ensures that sensitive information transmitted or stored in the blockchain remains confidential and secure.

Blockchain technology is perceived by people as something difficult to understand, but in fact the basic idea is simple. To understand the principle of the blockchain, let's find out how data is encrypted using cryptographic algorithms.

## Why encrypt data in the blockchain

Thanks to encryption algorithms, blockchain technology is considered the most secure kind of peer-to-peer networks (a network where everyone is equal to each other). To begin with, let's figure out why to encrypt something in the blockchain.

In the traditional and understandable systems client-server the security is the responsibility of the company's server, which ensures the security of the storage of funds (the bank's server), It performs the following functions:

2. Monitors the safety of data. The server takes care of the confidentiality of user data and does not give attackers access to personal data and information.
3. Controls data change. Any change is agreed with the server before it takes effect. In this way, data integrity is maintained.

Since each node in the blockchain is both a server and a client at the same time, and there is no central server, cryptography is used for the above purposes.

Cryptographic encryption algorithms perform the above functions without outside interference and now we do not need a bank server for safe storage of funds. Cryptography also answers the question of which encryption algorithm to use for a particular purpose.

## Algorithm with hash functions

Blockchain developers needed a type of mathematical functions that easily encrypts information without the possibility of decryption — these are one-way functions.

An example of such a function is multiplication. If we only know the answer, then we cannot say for sure which two numbers were multiplied.

For example, ${\displaystyle X\times Y=6}$

Next, we need a type of one-way functions that turns information of arbitrary size into a cipher of a certain length, and these are hash functions. They convert messages into a set of characters (hashes) that can be conveniently and safely used in programming.

Such a set of characters (hash) can consist of both letters and numbers. Which numbers and letters will be in the hash, as well as how many of them there will be, depends on the hash function selected.

Let's take a closer look at the most famous one — SHA-256, which is also used in the Decimal blockchain.

### How the SHA-256 hash function works

The SHA-256 hash function is also used in the Bitcoin blockchain. SHA stands for "Secure Hashing Algorithm", and the number 256 is the amount of cache in bits.

The operation of the SHA-256 hash function is conceptually similar to the creation of fingerprints. To identify a person, you do not need to know all the information about him: it is enough to know his fingerprint. SHA-256 calculates such a "fingerprint" of texts, videos, images, music and other types of information.

The algorithm of operation can be described as follows:

• A message arrives at the input — a file up to 2 million terabytes in size.
• Mathematical transformations are performed.
• The output is a hash — a 64-digit number.

You can encode the text and see how the hash function works online here

SHA-256 encodes messages instantly. The hashes are very different even with a minor change in the message. The hash changes so much that it has absolutely no similarity between the new and old values. Thanks to this, the SHA-256 hash function guarantees that it is impossible to change the message without changing the hash.

A set of letters and numbers in a hash is a single 64—digit number written in a 16-digit number system. To find two different messages with the same hash, you will have to go through them for millennia, so if two messages have the same hash, then be sure: the messages are the same.

## Blockchain transactions

Without hash functions, the existence of a blockchain would be impossible.

The blockchain is unique in that it guarantees the immutability and anonymity of the data it stores, thanks to encryption algorithms. Any data is checked for authenticity before being entered into the blockchain, but no one can see it. The same thing as a banker checks the authenticity of banknotes lying in a closed safe. This is where the hash function helps.

The blockchain regularly updates the data by adding records of changes — transactions. When updating transactional information, any system is vulnerable to attack. Banks mitigate this risk with the help of a centralized architecture and one-sided strict control over user access rights. The blockchain does not have a centralized control body — it is replaced by cryptographic hash functions.

Transactions and their hashes are formed into blocks. The hash in each new block depends on the hash in the previous one. Thus, all transactions ever made can be expressed in one number — the hash of the last block.

By changing even one transaction in any of the previous blocks, all subsequent hashes along the chain will change — such a version of the blockchain will be considered invalid.

The whole principle of blockchain operation is based on hash functions. If one block changes, you will have to restore all subsequent blocks by iteration. To carry out such a search, there will not be enough of any existing computing power.