# Unlocking Ethereum: A Deep Dive into Cryptography and Key Management

Cryptography is the science and art of securing information by transforming it into a form that is unintelligible to unauthorized users. It involves techniques to encrypt data so that only someone with the correct key can decrypt and read it. The primary goal of cryptography is to protect the confidentiality, integrity, and authenticity of data.
**As I continue my journey into blockchain technology with BlockFuse lab**, now in my **second week**, I have become increasingly intrigued by the role of cryptography in securing decentralized systems like Ethereum In this article, I will introduce some cryptographic techniques used in Ethereum, specifically public key cryptography (PKC), which controls the ownership of funds through private keys and addresses.
# Private key
This is a randomly generated 256 bits secret number used in cryptocurrency to sign transactions, messages and other data. it allows you to prove ownership of a blockcahin address and authorise transactions.
### Range of a private key
A private key can be any nonzero number up to a very large number slightly less than 2<sup>256</sup> — a huge 78-digit number, roughly 1.158 * 1077.
A simple python program showing how a 78 digit number(length of a private number) looks like

## Generating Private key
To create a private key, we randomly pick a 256-bit number and check if it is within the valid range(1 to 2<sup>256</sup> ). 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.
The public key is usually represented with a small letter **k**.
# Public key
This is a point K on the elliptic curve which is obtained by the the elliptic multiplication of the private key(**k**) and Genrator poin(**G**).
mathematically,it is represented by the formular
**k** = **k** * **G**
where,
Upppercase (**K**) is the public key.
\
Lowercase (**k**) is the private key.
**'*'** is the sign for Elliptic curve multiplication.
**G** is a fixed point on the **secp256k1** curve, known as the generator point. it is the same for all implementations of **secp256k1**, and all keys derived from that curve use the same point **G**.
**secp256k1**:
**secp**: This stands for "Standards for Efficient Cryptography Prime." It's a standard set by the Standards for Efficient Cryptography Group (SECG).
**256**: This refers to the size of the prime number that defines the field over which the elliptic curve is defined. In this case, it's a 256-bit number, which provides a high level of security.
**k1**: This indicates the specific curve used, characterized by particular parameters that define its shape and properties.
The result, Uppercase (**k**) is a point **P**=(x,y) on the elliptic curve,which is the public key.
## Generating Public key
Starting with a private key in the form of a randomly generated number **k**, we multiply it by a predetermined point on the curve called the generator point **G** to produce another point somewhere else on the curve, which is the corresponding public key K:
K = k * G
# Elliptic curve multiplication
in simpler terms , it is the repeatative addition of a point **G** (Generator point) by the private key (**k**).
For example if the private key,k is 2
then K=2*G, this is not same as 2 multiple by G but it is G + G
note that G is a point(x,y) on the curve
so k = G+ G
in order to peform this addition, you will need to find the slope(**λ** ) for for each cordinate G using the formular to Obtain The third point.
**λ** = **y<sub>2</sub> - y<sub>1</sub>/ x<sub>2</sub> - x<sub>1</sub>**
where,
**λ** represents the slope of the line connecting two distinct points on the elliptic curve.
After performing the public key using the above formular, the value obtain is check using the elliptic curve equation
y<sup>**2**</sup> mod p = (x<sup>3</sup> + 7) mod p
where
**p** is a finte field of prime number.
Below is the image showing the image of an an **elliptic curve**

Reference
Antonopoulos, A. M., & Wood, G. (2018). Mastering Ethereum: Building Smart Contracts and DApps. O'Reilly Media. Retrieved from https://github.com/ethereumbook
Carbon. (2024). Image created using Carbon. Retrieved from https://carbon.now.sh/