Dive into the Basics of Cryptography and Bitcoin
Did you know that Bitcoin and cryptography are deeply connected? Yes, it may sound strange, but the entire foundation of Bitcoin rests on the use of public-key cryptography and hashing functions. Let’s take a dive into the basics cryptography and Bitcoin in this blog. This is including: why it’s useful and how it relates to Bitcoin.
What is Cryptography
In a basic sense, cryptography is “secret writing”. At least that’s what the Greek roots of the words “kryptós” and “graphein” mean. Cryptography can be used to record information so that it will be hidden from a third party. Cryptography can also be used to ensure that the person who sent you a message is, in fact, who they say they are.
Computational Cryptography – Three Branches
Cryptography is a very complex science, but there are three major branches of modern, computational cryptography:
- symmetric-key
- asymmetric-key (or more commonly “public-key”)
- hashing functions
Sytmmetric-key Cryptography
In symmetric-key cryptography, a single key is used between the sender and receiver both to encrypt (or disguise) and decrypt (or reveal) a message. Bitcoin does not use symmetric-key cryptography, so let’s move on to the other two branches and learn about their importance.
Public-key Cryptography
Public-key cryptography uses (wait for it) a public key and a private key for message exchanges. Public keys are allowed to be published so that anyone can see them; private keys must be never be shared (complicated stuff, eh?) We owe a debt of gratitude to the company RSA for first describing the algorithm back in 1977. At its very simplest, this algorithm requires an attacker to factor very large prime numbers in order to decode the key and decrypt the message. “Large” numbers in this case presently start at 2,048 bits – try wrapping your head around that large a number!
The use of a public and private key can allow for two different modes of encrypting a message. In the first, an entity, let’s say Alice, retrieves a public key from her friend Bob. If Alice uses Bob’s public key to encrypt a message, only Bob will be able to decrypt the message. Hence, Alice can send Bob a secret message. But what about the authenticity of the message? How does Bob know Alice sent it?
The second major use of public-key cryptography is to digitally “sign” a message, verifying that Alice did, indeed, encrypt the message in the first place. Alice can use her private key to “sign” a message such that anyone with Alice’s public key can decrypt the message and verify that only Alice could have sent it. The public and private keys are irrevocably linked, allowing for anyone who so desires to prove that a message originated from Alice. Remember this point – Bitcoin uses it extensively, so we’ll talk more about it later.
Alright, there’s our first building block. Let’s talk about hashing functions and then move on to a discussion of how these elements play a role in Bitcoin specifically.
Hashing Functions
Hashing functions have two key features:
- Take an arbitrary-length input and produce a fixed-size output
- Scramble the output such that there’s no way to identify that it came from a given input.
This means that an entire file, say a 1 GB application file, can be hashed to produce a 256-bit output that uniquely identifies the file. Why is this important? If I am given a file and a hash, I can reproduce the hash and verify that that a given file has not been modified in any way.
Phew, we made it through the technical details. Now how does this relate to Bitcoin specifically?
Bitcoin Uses
Everyone using the cryptocurrency has a “private key”, but did you know that this private key is simply a key produced via the methods of public-key cryptography discussed above? Bitcoin uses the secp256k1 method of elliptic curve cryptography to produce a pair of keys that are 256 bits long (try using that bit of knowledge at your next dinner party!).
Let’s say Alice wants to send a Bitcoin to Bob. Alice creates a message or “transaction” and attaches Bob’s public key to the transaction. Alice signs the transaction with her private key, guaranteeing that anyone who looks at it knows Alice was the sender. How? Alice’s public key is linked to her private key. If someone is able to decrypt Alice’s signature with her public key, then they know that it MUST have been Alice who originally signed the message. Of course, there are quite a few more details we could discuss concerning a transaction, but at its very core, a transaction is simply a message that utilizes public-key cryptography to verify the authenticity of a sender. Pretty cool!
Blockchain and Hashing
Now where does hashing come into play?
The infamous blockchain in Bitcoin is a long sequence of blocks each linked to its previous block via a hash. This is where the “decentralized” nature of Bitcoin shines. No central server contains the private keys necessary to validate the transactions in Bitcoin; this is all done in the ledger.
Beginning with the genesis block (the very first block in the blockchain), every single block can be traced back one by one. This is the beauty of a decentralized currency system – there is no one in charge of the system as everyone can easily verify every transaction that has ever occurred by working their way through the blockchain.
Basics of Cryptography and Bitcoin
In this post, we’ve only struck the tip of the proverbial iceberg – there’s so much more to uncover about the basics of cryptography and Bitcoin. The math behind it all is complex but incredible. If you want to do some more reading on the topics we’ve covered, check out some of these links:
- The original Bitcoin whitepaper. This is what started the revolution. Take a look and make Satoshi proud.
- Here’s a pretty detailed look at the cryptography behind Bitcoin.
- This paper is a little easier to understand but includes some interesting details.
- This one’s in the name: Bitcoin Explained Like You’re Five
- And last, but not least, another short wiki detailing the inner workings of Bitcoin.
I hope you’ve enjoyed this post on basics of cryptography and Bitcoin! Bitcoin, and other cryptocurrencies, are incredibly intricate and fascinating. Only time will tell which cryptocurrency will become the next major player in the game – so be sure to check back for a detailed look as it all unfolds!