It is time to take a deep breath. To really understand Bitcoin and cryptocurrencies at more than just a superficial cocktail party level you will have to understand a few concepts from a branch of mathematics called cryptography. The section on cryptocurrencies will assume you are familiar with the concepts discussed here.
Don’t skip this chapter—it’ll be fun. Cryptography is, among other things, about sending secret messages that can be read only by the intended recipient. It is the stuff that spies use. We will cover encryption and decryption (the encoding and decoding of messages), hashing (turning data into fingerprint digests), and digital signatures (proofs that you have created or approved a message).
Cryptography is, however, not just for spies, criminals, and terrorists. It is now used extensively to protect data that travels across the internet. The ‘s’ in ‘https’ stands for secure. It means that cryptography is being used to guarantee that the website you think you are visiting is in fact the genuine website. It also means that the data in flight between you and that website is encrypted or jumbled up, so snoopers can’t easily read the communications between your device and the website that you are accessing.
Although cryptography is used for many more purposes than simply encrypting and decrypting secret messages, encryption is the most well-known use of cryptography, so let’s start with this. Blockchains are not generally encrypted, but understanding encryption provides a good background to cryptography which is used extensively in blockchains.
Encryption is the process of turning a plaintext (i.e., readable) human message into cyphertext (a jumble, gobbledegook), so that if the encrypted message is intercepted a snooper can’t understand it. Decryption is the process of turning the gobbledegook cyphertext back into readable plaintext. ‘Breaking’ the cyphertext means working out how to decrypt cyphertext without being given the ‘key’ (see below).
Let’s say Alice wants to send a message to Bob, so that only Bob can read it (it is always Alice and Bob, and we will see why later). Alice and Bob first agree on a scheme. Let’s use a very simple scheme where they encrypt the text by shifting each letter a set number of places later in the alphabet. They agree to use ‘+1’ as the ‘key,’ meaning that each letter is moved one place later in the alphabet. So A becomes B, B becomes C, C becomes D etc. This scheme is called the Caesar cipher.
Alice writes the plaintext note ‘Let’s meet, Bob’.
Alice encrypts it by shifting each letter once to the right: ‘Mfu’t nffu, Cpc’.
Alice sends the cyphertext to Bob.
Bob decrypts the cyphertext by shifting each letter back by one position and gets back the plaintext: ‘Let’s meet, Bob’.
This type of encryption is part of a family called ‘symmetric encryption,’ because the same key (+1 in this case) is used in both the encryption and decryption stages.
This method of encryption is not used in real life nowadays. Firstly, because it is too easy to spot and break using techniques such as letter frequency analysis. Secondly, and more importantly, Alice and Bob first had to communicate to agree what key to use for the scheme. They had to agree on the ‘+1’ in the first place. How do they know that someone wasn’t snooping when they agreed that?
Perhaps Alice and Bob met physically earlier and agreed on the ‘+1’ in person, but if they suspect at any stage that a snooper has compromised them, either in that meeting or during the course of their conversations, how would they then agree on a new key without the snooper being aware of that new communication?
In a world where our devices are constantly initiating connections with new websites, any initial ‘handshake’ where a symmetric key is agreed and shared between your device and the website is a weak point, and any eavesdropper who snoops on that initial exchange can decrypt the secret messages for the rest of the conversation. So later we will explore asymmetric cryptography, a much more commonly used form of encryption.
How is encryption relevant to blockchains? Actually, it is not very relevant. Many journalists and management consultants talk about encrypted blockchains, but they are confusing encrypted data, not used in first generation blockchains66, with cryptography which is used extensively in blockchains for hashing and digital signatures, as we will see later. Nothing on the Bitcoin network is encrypted by default. The whole point is that plain text transaction data is replicated across the network so that anyone can read and validate it.
However, other cryptographic schemes such as public key schemes, discussed next, are used extensively in Bitcoin, as are cryptographic hashes.
Public Key Cryptography
The Caesar cypher just described is known as a symmetric cypher because the same key is used to encrypt and decrypt the message. In public key cryptography, the key used to decrypt a message is different (but mathematically linked) to the key used to encrypt the message. Public key cryptography is described as an asymmetric scheme, because the key used to decrypt the message is not the same as the key used to encrypt it. This makes it more secure.
Using asymmetric cryptography, if you want to receive encrypted messages you create two mathematically linked keys: a public key and a private key. Together they are called a key pair. You can share your public key with the world, and anyone can use it to encrypt messages for you. You use your private key, known only to you, to decrypt those messages. Anyone who sends you encrypted messages using your public key knows that only you can decrypt them.