# DIY Binary

### Everything in digital data is binary

In computer science, "binary" refers to a system of representing data and information using only two symbols: 0 and 1. This system is the foundation of digital computing and is used to store, process, and transmit information in computers and other digital devices.

The binary system contrasts with the decimal system (base 10), which uses ten symbols (0 through 9). In binary, each digit is referred to as a "bit" (short for binary digit), and a sequence of bits forms binary code.

Here's how binary works:

1. **Bit:** The fundamental unit of binary is the bit, which can represent either a 0 or a 1. It's the smallest unit of data in computing.
2. **Byte:** A group of 8 bits is called a byte. Bytes are commonly used to represent characters, numbers, and other data in computer memory.
3. **Binary Numbers:** Binary numbers are composed of 0s and 1s. Each digit's position in a binary number represents a power of 2, just as each digit's position in a decimal number represents a power of 10. For example, the binary number 1010 represents:

   (1 \* 2^3) + (0 \* 2^2) + (1 \* 2^1) + (0 \* 2^0) = 8 + 0 + 2 + 0 = 10 (in decimal)
4. **Binary Operations:** Binary numbers can be operated on using binary arithmetic, which includes addition, subtraction, multiplication, and division. These operations are similar to their decimal counterparts but involve carrying over or borrowing in different ways due to the limited symbols (0 and 1).
5. **Data Storage:** Computers use binary to store and process all types of data, including text, images, audio, and program instructions. Each piece of data is represented as a series of binary numbers.
6. **Machine Language:** Computer processors execute instructions in machine language, which is represented using binary code. Each instruction is encoded in binary and corresponds to a specific operation or action.
7. **Digital Circuits:** Binary is used to represent electrical signals in digital circuits. Logic gates manipulate these signals to perform calculations and process data.
8. **Binary Representation:** Binary representation is often seen in hexadecimal (base 16) and octal (base 8) formats for convenience. These systems group binary digits into sets of 4 or 3, respectively, to make long binary strings easier to read.

Binary's simplicity and efficiency in electronic devices make it the ideal foundation for modern computing. It allows computers to process complex tasks using combinations of simple 0s and 1s, enabling the incredible range of tasks and functions that computers perform today.

### Bitcoin private keys and bits

Bitcoin private keys are critical components in the security and ownership of your Bitcoin holdings. They are used to generate digital signatures that prove ownership and authorize the spending of Bitcoins associated with a specific address on the Bitcoin blockchain. Without a private key, you cannot access or control your Bitcoins. Private keys are mathematically linked to public keys and Bitcoin addresses.

The relevance of Bitcoin private keys lies in their role as the ultimate cryptographic secret that grants access to your funds. They ensure that only the person with the correct private key can control the associated Bitcoin holdings. Private keys should be kept secure and never shared with anyone, as anyone who gains access to your private key gains control over your Bitcoins.

The size of a Bitcoin private key in binary bits is 256 bits. This corresponds to a private key length of 64 hexadecimal characters when represented in the more commonly used hexadecimal format. The reason for this specific length is related to the security of the Bitcoin network and the underlying elliptic curve cryptography used in Bitcoin's cryptographic operations.

It's important to note that the private key space is massive due to its 256-bit length, making it extremely difficult to guess or brute-force a private key. However, this also means that if you lose your private key, there is essentially no way to recover your Bitcoins associated with that key. This emphasizes the need to securely back up your private keys and store them in a safe and accessible manner.

Overall, understanding the significance of Bitcoin private keys, their role in securing your assets, and the importance of safeguarding them is essential for anyone involved in cryptocurrency ownership.

### How big is 256 bits (32 bytes) in digital size?

To understand the size of 256 bits, it's helpful to compare it to various contexts:

1. **Binary Numbers:** 256 bits can represent 2^256 (2 raised to the power of 256) different binary values. This number is approximately 1.1579209e+77. In other words, there are more possible 256-bit binary numbers than there are atoms in the observable universe.
2. **Key Space:** The term "key space" refers to the total number of possible values a cryptographic key can take. A 256-bit key space is extremely large and offers an enormous number of potential combinations. This makes brute-force attacks (attempting all possible combinations) on a 256-bit key computationally infeasible with current technology.
3. **Encryption Security:** The length of a cryptographic key, such as a Bitcoin private key, directly impacts its security. Longer key lengths provide higher security, as the number of possible keys increases exponentially with key length.
4. **Password Strength:** A password or passphrase with 256 bits of entropy would be incredibly strong and resistant to password cracking attempts.
5. **Hash Functions:** Many cryptographic hash functions, such as SHA-256 (used in Bitcoin), produce 256-bit output values. This output is often referred to as a "hash" and is used to uniquely represent input data.
6. **File Size:** A 256-bit value is 32 bytes (8 bits per byte). In comparison, a typical sentence in English text might be around 50 to 100 bytes long, showing the relatively compact size of a 256-bit value.
7. **Secure Communication:** In secure communication protocols, keys are often exchanged between parties. A 256-bit key ensures a high level of security against unauthorized access.
8. **Digital Signatures:** In digital signatures, a 256-bit private key is used to generate a digital signature that provides authentication and integrity for messages or transactions.

In summary, 256 bits is a substantial value in the context of cryptography and computer science. It represents an incredibly large key space and offers a high degree of security, making it suitable for sensitive operations such as generating private keys, creating digital signatures, and protecting data through encryption.

### ARTSNL code snippet of bits to uncompressed public key conversion

{% hint style="info" %}
The following is a javascript code snippet from the codebase of ARTSNL.
{% endhint %}

```
let binary = "1010100101000101011010101101010010100101010010010100111010100101001010010101110010100100101010010100101001111011001010100101001010010100101001010010100111100001010101001010101010010101011001111100101010010101010010101111001010100101010010100101111010101010"
let bigIntBinary = BigInt("0b" + binary)
let decimalString = bigIntBinary.toString(10)
let hexString = bigIntBinary.toString(16)
let privateKeyBuffer = Buffer.from(hexString, "hex")
let keyPair = ECPair.fromPrivateKey(privateKeyBuffer, Mainnet)
let eccPubKeyBuffer = ecc.pointFromScalar(privateKeyBuffer, false)
```

Important to note that ARTSNL utilizes the uncompressed public key due to its usage in the creation of an ethereum public address.
