> For the complete documentation index, see [llms.txt](https://docs.proudnet.com/proudnet.eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.proudnet.com/proudnet.eng/proudnet-note/notes/encryption_decoding.md).

# Encryption and decryption

When a message is passed from one computer to another, it is easy for it to be hacked, with a third party decrypting or tampering with its contents.

So, to encrypt a message, there must be an algorithm for encryption and decryption. However, since this algorithm alone cannot solve the problem, there must be a means to prevent the encrypted message from being decrypted even if an obvious algorithm is in front of us, that is, a key. Key-based encryption is commonly used as an encryption algorithm, and the length of the encryption key varies from 1 bit to several hundred bits.

Even if a hacker manages to obtain the encrypted message and even the algorithm, he must have the key to decrypt it. If the key is 128 bits long, then one of 2^128 encryption keys would be correct, which would take 10,790,283,070,806,014,188 years, even with a multi-billion supercomputer that takes 1/1,000,000,000,000 seconds to crack.

<br>

## Asymmetric and symmetric keys

Cryptographic keys are broadly categorized into <mark style="color:orange;">asymmetric</mark> and <mark style="color:orange;">symmetric keys</mark>. An <mark style="color:orange;">asymmetric key</mark> is a pair of keys, meaning that encryption with one key cannot be decrypted without the other. A <mark style="color:orange;">symmetric key</mark> requires that the key used to encrypt and the key used to decrypt are the same. Taking advantage of this property, computer networks often mix <mark style="color:orange;">symmetric</mark> and <mark style="color:orange;">asymmetric</mark> <mark style="color:orange;">keys</mark> to transmit encrypted messages.

For example,

Host A wants to securely deliver an encrypted message to Host B. A creates a pair of <mark style="color:orange;">asymmetric</mark> <mark style="color:orange;">keys</mark>, keeps one for himself and sends the other to B. The key that A owns is called the <mark style="color:orange;">Private Key</mark>, and the key sent to B is called the <mark style="color:orange;">Public Key</mark>.

<figure><img src="/files/Dz3767bw27uGuh7GTRYM" alt=""><figcaption></figcaption></figure>

B encrypts the <mark style="color:orange;">public key</mark> received from A with its <mark style="color:orange;">symmetric key</mark> and sends it to A. A decrypts the received <mark style="color:orange;">symmetric key</mark> with its private key and shares the <mark style="color:orange;">symmetric key</mark> created by B. In this process, even if the hacker obtains the <mark style="color:orange;">public key</mark> and the encrypted <mark style="color:orange;">symmetric key</mark>, he or she does not have the private key and cannot know the contents of the <mark style="color:orange;">symmetric key</mark>.

<figure><img src="/files/c5AezQQC5vyJVxhZDlZP" alt=""><figcaption></figcaption></figure>

Now, A encrypts the contents of the message with the <mark style="color:orange;">symmetric key</mark> it received from B and sends it back to B. B can decrypt the encrypted message with the <mark style="color:orange;">symmetric key</mark> to verify its contents. Again, the hacker cannot decrypt the message because he does not have the <mark style="color:orange;">symmetric key</mark>.

If a hacker tampered with the message and sent it to B, B would not be able to decrypt it.
