# What is Cryptography?

Site: | Saylor Academy |

Course: | CS120: Bitcoin for Developers I |

Book: | What is Cryptography? |

Printed by: | Guest user |

Date: | Wednesday, September 11, 2024, 12:01 AM |

## Description

Bitcoin is called a cryptocurrency because of its heavy use of cryptography. Here we'll take a quick look at symmetric and asymmetric encryption, as well as the two cryptographic functions that Bitcoin uses: digital signatures and hashing.

## Cryptography

Cryptography is a branch of math that is used to secure communications, to hide them from adversaries. The word "cryptography", or "crypto" is a Greek word that literally means "hidden", or "secret". And we are very used to thinking of cryptography as a tool for securing private data. Cryptography is what is used to create that green lock that you see in your browser when visiting a website with sensitive data. It's what is used to hide your credit card number when you are shopping online. But the branch of math that is cryptography includes a wide variety of functions that serve many purposes besides just the hiding of data. In fact, Bitcoin doesn't encrypt any data at all. All of the data on the network is public. However, Bitcoin makes heavy use of other cryptographic functions.

Let's take a quick look at some of those functions. We'll start with symmetric cryptography, then asymmetric, or public and private key cryptography, and then introduce two cryptographic functions that are used heavily in Bitcoin, hashing and digital signatures.

Source: Saylor Academy

This work is licensed under a Creative Commons Attribution 4.0 License.

## Symmetric Encryption

Encryption is the practice of scrambling data such that only the people you want to see the original message are able to do so. The first forms of cryptography used symmetric encryption. Let's explain this by starting with our two best friends in cryptography, Alice and Bob.

Alice and Bob want to exchange secret messages with one another. To hide the contents of the message, they will encrypt the data using a secret, or "key". In modern cryptography, these secrets involve sophisticated mathematics, but an encryption secret could be as simple as the instructions to move each letter of a message forward two letters in the alphabet to encrypt, and the instructions to move backwards two letters in the alphabet to decrypt. Using this algorithm, "hello" becomes "jgnnq". While simple, even this method effectively scrambles a message making it unreadable to those without the secret, or key.

Alice can use this method to encrypt her private messages to Bob and, if Bob knows the secret, then he can decrypt and read that message. He can also use this same secret to encrypt messages back to Alice. This method is called symmetric encryption, and while it works, it has one big flaw. How do Alice and Bob decide on an encryption algorithm, or secret key, for their communication? And if Alice decides on a secret to use in their encryption, how does she communicate that secret to Bob without someone else seeing it?

## Asymmetric Encryption

This key exchange problem is a big part of why asymmetric encryption has become so popular. It allows Alice and Bob to communicate securely without having to first agree on a shared secret or key. In asymmetric encryption, both Alice and Bob have two keys, a private key and a public key.

Let's see how asymmetric encryption changes Alice and Bob's communication. Alice now generates a key pair, a private key, and a corresponding public key. Bob also generates a key pair, one private and one public. The math that makes this all possible is very interesting, but what is important to know here is that what gives this method so much utility is that a public key can be used to encrypt a message, but the corresponding private key is required to decrypt that message.

With asymmetric encryption, Alice can give her public key to Bob and can do so out in the open. She can share it in a Tweet and pin it to her profile if she likes! Bob can then use that public key to encrypt a message to Alice in a way that makes it infeasible for anyone to be able to decrypt that message without Alice's private key. Not even Bob can decrypt that message. Once that message has been encrypted with Alice's public key, Alice's private key is the only key that unlocks that puzzle.

This means that now Alice and Bob can exchange public keys with one another out in the open, and then use each other's keys to encrypt their private messages. Alice uses Bob's public key to encrypt messages to him, which can be decrypted with his corresponding private key.

While these public and private keys were a huge advancement in cryptography, they can also be used for other functions, such as cryptographic signatures.

## Hashes

A hashing algorithm takes data, any amount of data, and produces from it a fixed-length unique identifier. Changing even one bit in the data feed into a hashing algorithm will produce a very different hash, and there is no way to guess what the hash of any given data will be. Hashing is what is called a one-way function. A hash can be easily produced from data, but that hash can not be turned back into the original data. Or at least cryptographers have yet to discover how to do this with any decent hashing algorithm.

Hashes have some very interesting utility. They can be used as unique identifiers, they can be used to represent data while obscuring the data itself, they can be used to detect any data tampering, and they are used in a unique way in Bitcoin's Proof-of-Work mining.

## Signatures

Cryptographic signatures use asymmetric cryptography to provide a strong assurance that a signed message is authentic and has not been tampered with. While a cryptographic signature uses a private key, it is a different function than encryption. A signed message does not need to be encrypted.

The first thing Alice will do is make her public key just that, public. She can share it on social media, add it to a key server, post it on her website, etc. She then composes a message to Bob and uses her corresponding private key to sign that message creating a digital signature. Then she can transmit the message and signature to Bob.

Once Bob has received that message, he can run the message, signature, and Alice's public key through a signature validation function that will tell him if Alice's public key is part of the key pair that was used to create the signature from the message received. If Bob is able to validate the signature then he can be reasonably assured that the message was indeed signed by Alice and that the message has not been altered in any way.

We can already see how digital signatures are a necessary security component in Bitcoin. They are used in Bitcoin to sign transactions, which prevents fraud by preventing anyone from forging a transaction or altering transaction data.