The word "cryptocurrency" has two components to it - "cryptography" and "currency." As you can imagine, cryptography is at the heart and soul of cryptocurrency. Asymmetric and symmetric encryption are the two main cryptography methods, and this guide breaks them both down. Read on for a fascinating insight into the world of cryptographic encryption!
Cryptography constructs and analyzes protocols to prevent outside parties from reading confidential information. Cryptography utilizes mathematics, physics, communication, information technology, and computer science. Aside from cryptocurrencies, cryptography is widely used in fields like computer passwords, military comms, and electronic commerce.
The goal of cryptography is to convert plaintext to ciphertext and back. Plain text is just a standard text written in any human-understandable language, like English, and it is easy to decode. On the other hand, the ciphertext is the encrypted version of the plaintext file, which the general user can't understand. All this happens via the following two processes:
This change from encryption to decryption and back can either happen with one key or with two. The former is symmetric encryption, while the latter is called asymmetric encryption.
First up, we have symmetric cryptography. With this type of key cryptography, the sender and receiver of a message share a single key. This key serves as a shared secret between the two parties involved during the cryptography process. There are two kinds of symmetric encryption:
A stream cipher uses a fixed key to combine plaintext with a pseudorandom string of characters called "keystream." It creates ciphertext by replacing each character in the plaintext with the corresponding digit of the keystream. A random seed value generates this keystream.
Let's look at how this form of cryptography works. We will take a simple example. Suppose Alice wants to send a message "MEET" to Bob. The keystream that they both decide to use is "BBBB."
The first thing that Alice does is numerically map on the file text and keystream (A-Z gets mapped to 0-25). So, this is how her message and keystream get mapped:
Now, she adds the digits with each other and mods each digit with 26. This gives her:
Now, if we map these digits to their corresponding alphabets, we get -> NFFU. This is the ciphertext that Alice sends over to Bob along with the key "BBBB."
So, how does Bob get back the original message? Via the decryption process.
Firstly, Bob maps both the ciphertext and the key to their numerical equivalent:
Now, Bob will subtract the two and subtract each digit with 26:
Now, if map these digits to their corresponding alphabets, we get -> MEET.
So, by sharing the key, both Alice and Bob were able to go from file text to ciphertext and ciphertext to file text, respectively.
A block cipher uses a deterministic algorithm, along with a symmetric key to encrypt a block of text, instead of encrypting one bit at a time. As such, this is a faster method than stream ciphers. To visualize how it works, imagine the block cipher to be a portal that takes in two inputs - the file text and key - and gives one output - the ciphertext.
Let's take a simple example.
While symmetric cryptography is pretty simple to execute, there are a lot of issues with this method:
James Ellis, a British mathematician, came up with the idea of asymmetric cryptography, i.e., using two separate keys for encryption and decryption. In this scenario, the receiver of the message is actively involved in the process as well, instead of just being a passive passenger.
To explain how asymmetric cryptography would work, Ellis gave the following example -
While this sounded pretty compelling on paper, we needed more practical implementation to execute this consistently in real-life scenarios. These implementations came in the form of - trapdoor functions and the Diffie–Hellman key exchange.
Think of what makes a trapdoor efficient:
A trapdoor function works similarly. A pretty famous example of a trapdoor function is your standard hash function. For example if we pass “100” through an SHA-256 hash generator, we will get AD57366865126E55649ECB23AE1D48887544976EFEA46A48EB5D85A6EEB4D306.
So, how is this is a trapdoor function?
In asymmetric cryptography, we use two keys - the public key and the private key. Information gets encrypted with the public key. The process of getting the ciphertext from the plaintext and the public key is straightforward. However, getting the plaintext from the ciphertext is extremely difficult. The only thing you can do is use the decryption key, aka, the private key.
Conceived by Ralph Merkle and named after Whitfield Diffie and Martin Hellman, the Diffie-Hellman key exchange is one of the fundamental tenets of public-key/asymmetric cryptography. Diffie-Hellman is a method of exchanging cryptographic keys over a public channel safely and securely.
Consider the following example.
Let's define some parameters before beginning:
Alright, so now that we have defined our parameters, let's look at the situation that we have at hand:
The two most commonly used asymmetric encryption algorithms out there are:
The RSA algorithm, named after MIT professors Rivest, Shamir, and Adelman, is a widely used asymmetric algorithm. The algorithm was derived directly from the Diffie-Hellman exchange. So, before we understand how it works, let's look at the parameters in play.
From the final equation, m = m^ed mod N, the values of our public key and private key are:
The public and private keys can be mathematically derived from each other. This derivation should satisfy the trapdoor function such that its infeasible for anyone to get the public key from the private key. To do this, RSA uses prime factorization.
What is prime factorization?
Every positive integer >1 can be written as a product of prime numbers (or the integer is itself a prime number). Eg. 14 is 7*2, while 256 is 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2.
Keep this in mind, let's take another look at the ciphertext equation we have derived above -> C= m^e mod N. The number "N," acts as the trapdoor function here. It is impossible to know the prime factors of N by just looking at it. However, if you know the value of the prime factors, you can easily find N by multiplying them.
So, we have determined "N." However, we still need to know the values of "e" and "d" to get both the private and public keys.
To get these values, we will be looking into another field of mathematics called "breakability" or phi().
If N is a random integer, then the output of phi(N) will be the total numbers of integers between 1 and N, which don't share any common factors with N, except 1.
Let's take an example. If N = 6. The numbers between 1 and 6 that don't share a factor, except 1 with 6 are 1 and 5. Since there are only two numbers that don't share a factor, the value of phi(6) = 2.
There are two interesting observations about the phi() function that you should know:
To understand the latter point, let's take a working example. Suppose we have a prime number 11. The only number between 1 and 11- 1,2,3,4,5,6,7,8,9,10,11 - which has common factors with 11 except 1, is 11. Hence, the value of phi(11) is 11-1, or 10.
Phi functions also happen to be multiplicative. Meaning - phi(A*B) = phi(A) * phi(B). Keep this in mind as we go back to our P1, P2, N.
We know that -> N = P1 * P2
If we phi() both the sides, we get: phi(N) = phi(P1 * P2).
By using the multiplicative property, we get -> phi(N) = phi(P1) * phi(P2).
Since P1 and P2 are both prime numbers, we can also write the above equation as:
phi(N) = (P1-1) * (P2-1).
Now, we finally get our trapdoor functionality. Suppose P1 is 13 and P2 is 19. That means N is (13*19 =) 247.
As per the formula -> phi(247) = (13-1) * (19-1) = 216.
If you know the value of a particular number's prime factors, it becomes very simple to find its phi().
Taking a look at what we have so far:
Now, to understand the last step of RSA, we need to bring both these aspects together. To do that, let's look at another theorem that Euler came up with.
For any two random numbers m and N that don't share a factor:
m ^ phi(N) ≡ 1 mod N
NOTE: The "≡" sign means "is identical to."
We will bring in a couple of modifications to this equation to make it more harmonious with the equations we already have.
We know that 1^k = 1 for all k.
In the equation -> m ^ phi(N) ≡ 1 mod N, we will multiply the LHS with 1^k (it won't make a difference in the output since 1^k is 1).
1^k * m ^ phi(N) ≡ 1 mod N.
m ^ k*phi(N) ≡ 1 mod N.
We know that for all m, m*1 = m.
Let's multiply both sides of our modified equation. We will get -> m*m ^ k*phi(N) ≡ m*1 mod N OR m ^ k*phi(N)+1 ≡ m mod N.
Now, let's compare this with another equation that we derived a little while back:
m ^ e*d mod N = m
Upon comparing the equation, we can see that they are pretty similar. By the process of substitution, we can derive the following conclusion:
e*d = k*phi(N) + 1
d= (k*phi(N) + 1)/e.
Finally, we have an equation that tells us how we can derive our private key (d) from our public keys, e and N.
This is how the RSA algorithm works.
Elliptic-curve cryptography or ECC is a form of public-key cryptography based on the algebraic structure of elliptic curves over finite fields. An elliptical curve is any curve that satisfies the following equation:
y^2 = x^3 + ax + b
Where (x,y) is a variable point on the curve, while a and b are constants.
NOTE: Image credit for the curves shown below -> CSBreakdown youtube
If you want to add two values V and A, we will trace them on the curve and run a line through them. We will then see where the line intersects the curve.
Following that, we draw a vertical line through the point of intersection. The place where the vertical line intersects the curve again is considered the point of addition, aka, V+A.
When we multiply a value with an integer, we are adding it with itself a specific number of times. For example, 3*X is X+X+X.
The same logic applies here. We have a value V and if we want to get 2V, we can add V with itself. We do that by drawing a tangent from V and vertically reflecting the point of intersection:
Now, if we need to find 3V, we can simply V and 2V:
Alice and Bob want to exchange messages over a public network without revealing their personal info. This is how it works:
Before we look into the process, let's declare some values:
Phase 1: Signing the message
We will determine two values r and s, which will be the coordinates of our signature.
The sender sends (r,s) to the verifiers for verification.
Phase 2: Message verification
Verification is a straightforward process. The verifiers will execute the following:
z*s^-1*G + r*s^-1*Q
Upon solving, this equation gives the point (x,y)
With the equation r = x mod n, the verifiers can solve for x and see if the values match. If it does, then the signature is valid.
ECC offers the same level of security as RSA by consuming far fewer bits. Consider the following:
The reason why ECC is so efficient is because of the speed with which it makes mathematical computation. For example, suppose we have a value P and we want to find 100P. Instead of just adding P to itself 100 times, it can do the following:
As you can see, a process that should have taken 99 steps took just 8.
The moment you get a Bitcoin wallet, you will receive your public address and private key.
How does the Bitcoin wallet generate your public address and private key?
It is essential that you first have a basic idea of asymmetric cryptography if you want to gain a good understanding of cryptocurrencies. In this guide, we have shown you how different symmetric and symmetric cryptographic processes work. You should now have a better understanding of some of the underlying processes that get triggered when you decide to interact with your cryptocurrencies. With a rising blockchain developer salary curve and decentralized finance (DeFi) on the rise, it is going to be more important than ever with cryptocurrencies and online blockchain schools. If you want to know more about cryptography, be sure to check out Ivan on Tech Academy and its cryptography course!
Get to work in a fast growing industry. Start learning blockchain together with our 20,000+ students today.
Use coupon code BLOG20 for 20% off.