Cryptography Simplified: A Beginners Guide

What is Cryptography?

Cryptography is the technique of hiding information (encryption) so that only a person person who is meant to see the information can read it (decryption).

It involves the secure transmission of information.

Cryptography = Crypt (Secret) + Graphy (Writing)

It converts the message into CipherText using encryption key and that CipherText is reverted back to original message using decryption key.

There are mainly 3 types of Cryptography:

  • Symmetric Cryptography (Private Key Cryptography)

  • Asymmetric Cryptography (Public Key Cryptography)

  • Hash

Etheruem uses Public Key Cryptography to generate key pair (public + private) & addresses which gives ownership of funds.

Let’s Understand Each Type Simply:

Symmetric Cryptography (Private Key Cryptography)

The Sender and the Receiver use the same shared secret key to encrypt and decrypt messages.

Encryption: PlainText combined with Secret Key produce CipherText (unreadable).

Decryption: CipherText combined with the same Secret Key revert back to PlainText (message).

Asymmetric Cryptography (Public Key Cryptography)

Public key cryptography is a core part of modern-day information security.

Used by Ethereum, in which keys come in pairs consisting of a private key and a public key.

Ownership of accounts is established through digital private keys, ethereum addresses, and digital signatures.

Public key is as similar to a bank account number,

Private key is as similar to the secret PIN.

Private Key → provides control over the accountPublic Key → identifies account to others

In the payment portion of an Ethereum transaction,

Public address → derived from public key, used same as the beneficiary account details of a bank transfer.

How Key Pair is Generated?

We will take example of Ethereum Ecosystem.

Key Pair Generation
Key Pair Generation

Generating Private Key

The first and most important step in generating keys is to find a secure source of entropy or randomness.

Creating an Ethereum private key essentially involves picking a number between 1 and 2^256.

A private key can be any nonzero number up to a very large number slightly less than 2^256 — a huge 78-digit number.

The exact number shares the first 38 digits with 2^256 and is defined as the order of the Elliptic curve used in Ethereum.

To create a private key, we randomly pick a 256-bit number and check that it is within the valid range.

In programming terms, this is usually achieved by feeding an even larger string of random bits (collected from a cryptographically secure source of randomness) into a 256-bit hash algorithm such as Keccak-256 or SHA-256.

Both of which will conveniently produce a 256-bit number.

If the result is within the valid range, we have a suitable private key.

Otherwise, we simply try again with another random number.

Generating Public Key

An Ethereum public key is a point on an elliptic curve, meaning it is a set of x and y coordinates that satisfy the elliptic curve equation.

The public key is calculated from the private key using elliptic curve multiplication, which is practically irreversible: K = k * G,

where k is the private key,

G is a constant point called the generator point,

K is the resulting public key, and

* is the special elliptic curve “multiplication” operator.

The relationship between k and K is fixed, but can only be calculated in one direction, from k to K.

That’s why an Ethereum address (derived from K) can be shared with anyone and does not reveal the user’s private key (k).

The Magic Of Public Key Cryptography.

Generating Public Address

Ethereum addresses are unique identifiers that are derived from public keys using the Keccak-256 one-way hash function.

Private key k:

k = f8f8a2f43c8376ccb0871305060d7b27b0554d2cc72bccf41b2705608452f315 

Public key K:

K = 6e145ccef1033dea239875dd00dfb4fee6e3348b84985c92f103444683bae…….

We use Keccak-256 to calculate the hash of this public key:

Keccak256(K) = 2a5bc342ed616b5ba5732269001d3f1ef827552ae1114027bd3ecf1f086ba0f9 

Then we keep only the last 20 bytes (least significant bytes),

which is our Ethereum address:

001d3f1ef827552ae1114027bd3ecf1f086ba0f9 

Most often you will see Ethereum addresses with the prefix 0x that indicates they are hexadecimal-encoded,

0x001d3f1ef827552ae1114027bd3ecf1f086ba0f9

Watch this video to have fun & visualise key pair:


Hash Function

A Hash function is “a one way function that can be used to convert data of any size to data of fixed size.”

The input to a hash function is called the input or the message.

The output is called the hash.

The “one-way” nature means that it is computationally infeasible to recreate the input data if one only knows the output hash.

Let’s take a closer look at the main properties of cryptographic hash functions.

These include:

  • Determinism

A given input message always produces the same hash output.

  • Noncorrelation

A small change to the message (e.g., a 1-bit change) should change the hash output so extensively that it cannot be correlated to the hash of the original message.

  • Irreversibility

Computing the message from its hash is infeasible.

  • Collision protection

It should be infeasible to calculate two different messages that produce the same hash output.

Resistance to hash collisions is particularly important for avoiding digital signature forgery.

Hash Functions used by popular Blockchains:

  1. Bitcoin (BTC):

    Hash Function: SHA-256 (Secure Hash Algorithm 256-bit)

  2. Ethereum (ETH):

    Hash Function: Keccak-256 (an Ethereum-specific variant of Keccak)

  3. Litecoin (LTC):

    Hash Function: Scrypt

  4. Bitcoin Cash (BCH):

    Hash Function: SHA-256 (similar to Bitcoin)

  5. Ripple (XRP):

    Hash Function: SHA-512

Watch this video to visualise hash function:


In Ethereum, communications between nodes (including transaction data) are unencrypted and can be read by anyone. This is so everyone can verify the correctness of state updates and consensus can be reached.

Advanced cryptographic tools, such as zero knowledge proofs (next article) are getting implemented which will allow for encrypted calculations to be recorded on the blockchain while still enabling consensus (game changing!).

These types of cryptographic proofs are mathematical tools critical to the operation of the Ethereum platform.

That’s all for now.
Thanks for reading.


Subscribe to arnavb
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.