Macroeconomic Monitor
Home / Economy / What is Bitcoin Part II: The Cryptography Behind Cryptocurrencies

What is Bitcoin Part II: The Cryptography Behind Cryptocurrencies

Author: Stilgar

This article aims to introduce non-programmers to how Bitcoin works on a technical level. How is it possible that there is no central server and no one controls it? Although the explanation is simplified, this is not a text with inaccurate metaphors, but a serious description with mathematics. Although the mathematics is at a maximum sixth grade level and simplified as much as possible, this is not an easy read for people who are not in the habit of reading mathematics-related texts. For cryptographic concepts that are too complex to be explained here (requiring 12th grade mathematics), only an explanation of what can be achieved with them is included. Fortunately, these tools existed before Bitcoin and Bitcoin uses them out of the box.

First, it's important to understand that everything in computers is a number. Text? We can give each letter a number and then have a sequence of numbers. A picture? Each pixel can be three numbers for red, green, and blue and the picture can be a sequence of numbers. A sequence of numbers arranged one after another can be treated as one very large number. Therefore, in the explanations below when we explain something about arbitrarily large numbers, it can be considered that it applies to any data.

The character numbers for uppercase letters of the Latin alphabet as defined in ASCII – American Standard Code for Information Interchange. Virtually all computers use these numbers for these characters. Lowercase letters have separate numbers. Characters like the comma or even invisible characters like the space also have numbers.

Public and private key

Public-private key cryptography has been around since the 1970s and is widely used all over the Internet. When you see a padlock next to an address in your browser, it means the link is encrypted and is using a similar cryptography. The public key is publicly available and is not a secret (although in some situations it may be a good idea to make it yours under a pseudonym, as Satoshi Nakamoto does).

The private key associated with it must be kept secret. The keys are two numbers related to the magic of mathematics. Very large numbers are chosen and are usually written with a little extra information in a base 64 (or other large base) number system to make them shorter. Here is an example set:

-----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQCDUb6HaTNpyNF8bn9/3X6cTiBkbWfbjPdZwjus0DlLXWfTFhhP 5fckSjn0j38UdPpFBasiA2B22BzAWnRClZ3OtPtMeogrnaNnj1ETBOU0wq2Ka+VV Xdb/UjURj+nVQeXmKjiw2XkkkR1FBRbAXkLRGKTdFy8g5Ozcbly/knQdTQIDAQAB AoGATaKRKor2W07fElpdRGHVTWEe42CO6wyO22DqWMONa9Hf5LqGSw4gqzK6yqvf LF/v6chtISGv8PLZJJsVapv7e/CO6UqwX962ngRXOW5/WPbAkYMhlSfQ8R+womf3 KALNNbjwVvV5bjm5j6NqWhMyvrHM6GPlqPpzCeuEvH7xGaECQQDiFrwUoGho52ws hZN7H+rRIlAr7cTDNgWP6oWy2ED6A3E37Zk680LmE4vTDf4GtKt2fN0gtAEoXnpF xu7V+FCpAkEAlLFRnIsXZUt2HDoxHi91ZHsjEsyEMV+yI2Fp4NMTBAoSHQkbFSry ed/bbZRNWyace2TRntdh8OYtyQ1vFRp6BQJBANRjwyAlaLBT5v0UJu3dl/wLHgGG hfdUwnjmOd8+5Bt6LFv76pzEda4p4orMdDzccM8IkbrtHsFLr9XpAekkMrECQFiw 58AbSwo1l67AmxmpLzmPJV2KNfOJZCUsbs4WuMn5A9Lj4o6evmEpwKW9BuMuxbno agx35kid04OQCskosM0CQFir7K7SjX0ZgsbehdMy1JBHcibr/4wqaKScmX1IukCN iaX0QngtfKE3jds2asvRUpxa7OiT2audl8xPdRkigwU=
-----END RSA PRIVATE KEY-----

-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDUb6HaTNpyNF8bn9/3X6cTiBk bWfbjPdZwjus0DlLXWfTFhhP5fckSjn0j38UdPpFBasiA2B22BzAWnRClZ3OtPtM eogrnaNnj1ETBOU0wq2Ka+VVXdb/UjURj+nVQeXmKjiw2XkkkR1FBRbAXkLRGKTd Fy8g5Ozcbly/knQdTQIDAQAB
-----END PUBLIC KEY-----

Keys are usually not distributed in plain text but are hidden in some files that the programs work with. For example, Bitcoin wallets usually have a special file in which the keys are encrypted (with a password). The letters and other symbols in the above example are used for numbers over 10 (A means 10, B means 11, etc.). The recording is not particularly important, just assume that these are very large numbers. They are generated by coming up with two large prime numbers that meet certain conditions and passing them through a procedure that produces the two keys. The two keys are "magically" connected and there is no way to efficiently (quickly) find the private key from the public key. It could be done with many attempts, but the reason we choose large numbers is to make sure that there are so many attempts that it is pointless to try by guessing even if all the computers in the world were to harness this. Through cryptographic algorithms, two things can be done with these two keys. The first is to encrypt data with the public key so that only the owner of the private key can decrypt it. This is done by converting the data into numbers and then mixing them with the key through a series of arithmetic operations. The encrypted data (called cyphertext) is mixed through arithmetic operations with the private key and thus decrypted.

The second operation, which is much more important for Bitcoin, is signing. A piece of information can be signed with the private key so that anyone can verify with the public key that the signature is exactly from the owner of the private key (corresponding to this public key). The data is mixed with the private key through arithmetic operations and a (large) number is obtained, which we call the signature. Then the data is given together with the obtained number (the signature) and with another algorithm, including the public key, the data and the signature, it is checked whether the signature is valid. Generating a “fake” signature is practically impossible. In practice, the verification is done with a program, and even more often it is built into the software (for example, the padlock in the browser means that the verification was successful).

Cryptographic hash functions

A function in mathematics is an operation in which a number (or more generally - data) x is associated with another number y such that each x corresponds to exactly one y, but each y can correspond to many x. Examples:

y = x + 5
y = 1 (for any x the result is 1)
y = 5 if x is between 10 and 20, otherwise y = 3

(Alternative notation is f(x) = x + 5, where f is the name of a function)

Hash functions are functions for which the argument can be any, but the value of the function is always in a certain interval and we usually want the function to be evenly distributed in the interval if the argument is evenly distributed. For example, we may want the result of the function to always be between 0 and 9 inclusive.

A simple such function is y = x mod 10 - where "mod" is division with a remainder and the result is the remainder, for example:

5 against 10 = 5;
15 divided by 10 = 5;
10 against 10 = 0;
23 mod 10 = 3 and so on.

It is taught in second grade, sometimes called "division modulo N", and in programming languages the symbol % is used, for example 23 % 10 is read as "23 divided modulo 10". You can think of this operation as "rolling over" - when we get to N we simply start again at 0. Modulo division is a frequently used operation in cryptography and programming. Note that if the argument x is uniformly distributed then the function (the results) will also be uniformly distributed in the interval [0, 9]. At the same time, if we take the above function

y = 5 and if x is between 10 and 20, otherwise y = 3

then the results will not be evenly distributed and there will be many more results of 3 than 5 because there are many numbers outside the interval [10, 20] and only 11 numbers in it. That's why we don't call this function a hash function.

But what is a cryptographic hash function? Our example of a hash function above can be reversed – it is possible to obtain an argument that corresponds to that result from a result. Cryptographic hash functions are constructed in such a way that the reverse operation cannot be performed with calculations. They are complex and involve interesting shuffles, and their results are very large numbers, so that it is difficult to find an argument through simple trials. The second requirement for a function to be a cryptographic hash is that collisions cannot be found (not known). A collision means that different data have the same hash. Collisions exist for all cryptographic hashes, but no one can find them. If a collision is found, the corresponding hash function is considered broken.

Another way to think about a cryptographic hash is as if, in advance, we have generated a random number for all possible inputs to correspond to them and we keep these numbers in a table. When we are given an argument, we check the table and pull out the random number (for the same input data, we always pull out the same number). The table is secret. Of course, in practice there is no way to do this because the potential inputs are infinite, but the goal of hash functions is to be indistinguishable in behavior from such a hypothetical hash function. The hash should be indistinguishable from a randomly generated one.

A cryptographic hash can be used to verify that a file is genuine. For example, a software manufacturer might put the hash of their software on their website and offer a link to download it from another location (such as a torrent or a foreign server). The user can download the file and verify that the hash is the same (by regenerating the hash using the algorithm of the corresponding hash function). If the hash is the same, then the file has not been altered and is exactly as the software manufacturer released it because no one could have composed a different sequence of data that would produce the same hash. (If it can, it is not a cryptographic hash function or the function is broken).

Bitcoin uses a cryptographic hash function called SHA-256. It is important to mention that with cryptographic hashes, even a small change in the data (for example, 1 letter in the text) leads to a completely different hash. I would like to point out again that everything mentioned so far has been used everywhere on the Internet for decades and was not invented for Bitcoin. All these things do not require a PhD in mathematics or computer science to understand and to make sure that they really work, and there are courses on the Internet (for example, https://www.coursera.org/learn/crypto ) that explain them, but they require several weeks of study. Understanding and taking the tests is possible without programming knowledge, but the practical tasks require programming because it is still difficult to calculate thousands of arithmetic operations by hand.

 

Did you like it? Take a minute to support the EKIP on Patreon!
Become a patron at Patreon!

About Guest Author

Read more

The financial coup in Bulgaria of 1947

The year 1947 in Bulgarian history is associated with the implementation of an important monetary reform. It is …