Category: Not So Easy Pieces

  • 5 Minute Japanese Lesson

    米軍ヘリの窓、校庭落下

    That is the headline from an article in the Yomiuri newspaper, December 14, 2017. Let’s yank it apart and see what it says and learn a little Japanese in the process.

    [米] is the kanji (Chinese character) for “rice”. There are thousands and thousands of kanji and take years to learn, but we’ll focus only on the ones in the headline. [米] is pronounced kome when it appears as a solo kanji and bei when it appears in combination with another kanji. In our headline it is in tandem with [軍] , so it’s pronounced bei in this case. Another use of [米] is in the kanji set [米国], or beikoku, which means “America”. It’s actually a shortened form of the original name for “America” which is [亜米利加], or Amerika. Today, [米] is often used to indicate that something is American as in [米大統領] or “American president”.

    Unfortunately, they had to use kanji to produce the phonetic sounds of words because the heathens wouldn’t use the ABC’s. For example, if you pile up the train wreck of nonsensical kanji [府亜区御府酢零馬] you come up with a reading of, “Fuck off, Slaver”. Sometimes for fun I’ll write, [味噌歩荷] on a piece of paper and have a young lady read it aloud. “Mi so ho nee? I no understand.”

    [軍] is pronounced the same as the English word “goon” (written as gun) and means “army”. So when we put [米] and [軍] together we get beigun or “rice army” or “rice goon” or, more accurately, “American Military”.

    Your average Japanese schoolyard

    [ヘリ] is written in katakana. Katakana is a system of 46 simple characters that is used for transcriptions of foreign words, loan words etc. [へ] is read as he (which is pronounced like “head” without the “d” sound) and [リ] is ri as in “reeeeeeeee”. [ヘリ] gives us heri which is the shortened form of [ヘリ コプター] or herikoputaa. Helicopter. For example, [ピノチェトのヘリコプター欲しい!] which means, “I want Pinochet’s helicopter!”

    [の] is no, and don’t you forget it. This is from the final system of writing called hiragana. Same number of characters as katakana, 46, and, as with katakana, can produce all the sounds you need in Japanese. Hiragana is basically the glue that holds a sentence together as it’s used for verb endings, prepositions and so on. [の] functions the same as the possessive “s”. [米軍ヘリの …] means, “American military helicopter’s…”

    Let’s speed this up. [窓] is mado and means “window”. [校] is kou and means “school”. [庭] is tei (or niwa when appearing solo) and means “garden”. [校庭] therefore is koutei or “schoolyard”. [落] is raku (or ochiru when solo) and means “fall”. [下] is ka (or shita when solo) and means “down”. So we can read the entire headline as, “beigun heri no mado, koutei rakka”.

    And there we have it, “American Military Helicopter’s Window Falls on Schoolyard”. This happened in Okinawa and similar incidents have happened over the years. Fortunately, none of the elementary school’s students were injured, but if a fatal incident were to occur due to U.S. military actions, you’d probably hear cries of, “Get these rice goons out of our schoolyard!”

  • A Deep Dive into Cryptocurrencies and Their Operation: Part 2

    In Part 1, we talked basic computer science. I highly recommend reading/re-reading Part 1 before reading this article if you don’t have a firm grasp on the basics of computer science.

    We’re going to start here in Part 2 by talking generically about some of the hurdles that cryptocurrencies have had to overcome, then we’ll define some terms, and finally we’ll put all the pieces together into a basic model of how a blockchain-based cryptocurrency works.

    Traditional Ways of Passing Data through an Untrusted Medium

    Let’s do a quick survey of a few ways that important data can be passed through an untrusted medium (i.e. the Internet). You’ll recognize some of these from Part 1.

    Encryption

    Pretend you have a secret message that you want to send from your computer to your friend’s computer. An easy example may be a message including your credit card information to purchase Glibertarians pink footie pajamas. How do you send that information from your computer, through a bunch of network devices (routers, switches, etc.) that are owned by neither you nor your friend, and to your friend without being intercepted by a nefarious third party?

    The easy answer is cryptography. Let’s change the message in a way that only your friend has the “key” to unchange it. There are many ways to do this, but one of the most common is public key cryptography. If you want more info on public key cryptography, check out Part 1.

    Secured Channels

    Sometimes, you’re sending a bunch of secret information across the network to the same place. The most common example is when you’re working from home. You’re transacting a bunch of secret information with your corporate servers, and it may be easier to just establish a secure channel between your computer and the corporate network so that you don’t have to manage the overhead of encrypting the info piecemeal. What am I describing? VPN.

    This doesn’t really have anything to do with blockchain, but it gives you a bit of context about how security can be implemented over the Internet.

    Trusted Authorities

    Trusted authorities also have nothing to do with blockchain, except to act as an opposing contrast to the way blockchain works. We talked in Part 1 about the two ways that public key cryptography can be used. One way is to securely send secret information across an untrusted link. Another way is to sign a message and validate that the message came from the person you think it did.

    What if I want to know that you’re legit before I send you all my personal information? STEVE SMITH could easily insert himself between  you and me, send me his public key, and then intercept and decrypt my response. This is called a “man in the middle” attack. Rather than just trust that the public key you supposedly sent me, I can reach out to a trusted 3rd party, who has your public key on file. I request your certificate from this trusted 3rd party (called the Certificate Authority), and compare the public key in the certificate with the public key you sent me to make sure it hasn’t been meddled with. The weakness of this method is that you have to trust the security of the Certificate Authority (the most well known CA is VeriSign).

    Blockchain uses some of the encryption technologies we have discussed, but specifically cannot use VPN or CA technology because blockchain is implemented in a completely trustless environment. Why is it a trustless environment? Because authority is distributed rather than centralized.

    Centralized, Decentralized, and Distributed: A Libertarian Way to Organize Things

    I’m going to keep this focused to the tech realm, but y’all are smart enough to expand these concepts outside the realm of computers. There are three main ways of organizing tech in order to accomplish a task. Centralized systems involve everybody reaching out to one single node (e.g. server or cluster of servers) in order to accomplish the task. Decentralized systems involve everybody reaching out to one of a small number of nodes in order to accomplish the task. Distributed systems involve everybody reaching out to everybody else in order to accomplish the task.

    Centralized

    Centralized systems are what we use on an everyday basis. I want to buy something from Amazon, so I connect to an Amazon server and make the purchase. You want something from Amazon, so you connect to an Amazon server and make your purchase. This is a centralized system*, everybody connects with an Amazon server in order to complete their transaction.

    * You could argue that Amazon runs a decentralized system, because there are Amazon servers all around the world to share the load of so many people shopping simultaneously. However, for this description, “centralized” refers to only one “entity”  being involved, no matter the number of physical servers.

    Decentralized

    Decentralized systems are less common, but are still used on a regular basis. I want to refinance my house, so I go to LendingTree or any one of the other online insurance brokers. I input my information, which is sent to a handful of banks and other lenders, and each lender returns the request individually. If one lender doesn’t respond, it’s not quite as efficient, but I still have access to all of the other lenders.

    Distributed

    What if we take it a step further? Rather than a handful of entities, everybody can be an entity and everybody interacts with everybody. For example, Uber. You submit a ride request, and other people choose whether or not they want to fulfill that request. Uber isn’t perfectly distributed, as there is a barrier to entry before you can drive for Uber, but the barrier is low enough that it’s essentially distributed for our purposes.

    How Transactions are Verified when Nobody can be Trusted

    We have two obstacles to get over before we can verify a transaction. The first obstacle is ensuring that nobody has stepped in and altered a legitimate transaction. The second obstacle is ensuring that legitimate creator of the transaction isn’t trying some funny business.

    We’ve already discussed a method for tackling the first obstacle, using public key signing. The person who is giving the money signs the transaction with their private key, and the public key is included in the transaction data. Then, anybody in the public can check the signature using the public key to make sure that the transaction was approved by the originator.

    What about the second obstacle? Well, that’s a little more complicated and involves some economic incentives. We’ll get into this in more detail in Part 3 of this series, but suffice it to say that pulling off a con to steal somebody’s cryptocurrency involves an impossibly large amount of computer resources, and an immense amount of luck. The incentive to steal is way overridden by the costs of acquiring the raw processing power required to make such a con even remotely possible.

    How does bitcoin get stolen, then? Usually some currency exchange website is hacked, and the private keys of users’ accounts (wallets) are compromised. It’s not a flaw in cryptocurrency, but in the exchange’s security. Blaming such hacks on cryptocurrency is like blaming the US Dollar because Chase’s system gets hacked.

    Definitions and Terms of Art

    Blockchain (Sometimes called distributed ledger technology) A list of connected messages that contain transaction information. The blockchain is copied to every node (computer) in the blockchain network, allowing each and every participant in the blockchain to examine the blockchain for inconsistencies.

    Cryptocurrency – A financial product that is transferred between people using a blockchain. Some people view cryptocurrencies as investment products (commodities). Others view cryptocurrencies as a currency. Many cryptocurrencies use a mathematical algorithm for “printing” new money that is rather deflationary, making them attractive long term investment vehicles.

    Bitcoin The original cryptocurrency that is trading for somewhere in the neighborhood of $11k per Bitcoin at the time of writing. You don’t have to buy full Bitcoins, but can buy as little as 0.0000001 Bitcoin.

    Smart Contract – Some uses of blockchain are less tightly coupled to currency. Ethereum, for example, is a broader use blockchain system, and includes smart contracts, which are publicly inspectable contracts that are mostly self-executing. For example, if getting the wifi password is keyed to paying your rent, the smart contract will retain the new month’s wifi password and will not release it to the tenant until rent is paid.

    Fork (of blocks in a chain) – A condition of the blockchain where two blocks are created and verified by different nodes in the network at substantially the same time. In such a situation, there is a “fork” until the next block is verified. Whichever forked block is retained by the node that verified the next block is the “winner”, ending the “fork.”

    Fork (of cryptocurrencies) – A split off of a new cryptocurrency from an old one. Usually this happens because the older cryptocurrency has some limitation or flaw that the new cryptocurrency resolves. Depending on the specific situation, the older currency may transform into the new currency.

    Merkle Tree – A type of binary tree (a hierarchical linked list where a “parent” node has at most two “children”) used to organize the cryptocurrency transactions stored within a block. Each leaf node (i.e. nodes without children) of the Merkle tree represents a transaction, and the parent nodes represent a combination of multiple transactions. Each node has a hash, with the root node (the parent of all parents) containing a transaction hash for the entire block. These hashes can be used to verify the accuracy of the transactions, and the transaction hash for the entire block is used in creating the hash for the block.

    Wallet – A data structure built around a user’s private key that retains all of the cryptocurrency that has been transferred to it.

    Exchange – A website that retains a cryptocurrency wallet for each of its users. Exchanges are like a cross between a bank and an investment broker.

    Blockchain? Is That Some New Type of Jewelry?

    Blockchain is the technical underpinning of cryptocurrencies. A blockchain is a linked list of data structures. Each data structure includes a header, a transaction ledger, and a pointer to the prior block.

    Here is a very high-level view of what a blockchain looks like. You have ledger of transactions arranged in a tree form (a tree is a linked data structure kind of like a linked list, but with more than one relationship saved in the structure. For example, in a binary tree, each “parent” data structure has two “children”). The actual transactions are located in the leaf nodes (a leaf node has no children), and the root is the top parent node. The Merkle tree (the specific type of binary tree used for blockchain transactions) calculates the hash of each transaction, and then continues to hash the combined hashes up the tree until we get what’s called the Merkle root hash (shown as “trans: H( )”). The specifics of how all this works isn’t super important, and it’s fairly intuitive once you understand hashing. You’re essentially taking hashes of hashes until you get one single hash that represents all of the transactions in the block. Why do we want that?

    Because the hash of the block (used for security/verification purposes) isn’t the hash of the ENTIRE block, but only of the header of the block. The actual transactions and the Merkle tree are contained in the transaction ledger, and are not taken into account when calculating the hash of the block. However, the Merkle root hash (which takes into account all of the transactions) is located in the header of the block and is thus taken into account when calculating the hash of the header of the block. If a nefarious actor tried to change one of the transactions to route currency to his wallet, it would change the Merkle root hash, which would change the hash of the block, resulting in it being obvious to the blockchain network that something has been tampered with. We’ll go into more detail on this in Part 3 of the series.

    The last concept I want to bring up in this article is the increasing security over time. How does that work? Well, it has to do with the linked list of blocks. Let’s say we have three blocks that STEVE SMITH wants to corrupt in order to steal some cryptocurrency.

    STEVE SMITH will have the easiest time corrupting block C. Why? Because all he has to do is change the transactions and calculate the new hash for C. I say “all he has to do” as if it’s easy. We’ll talk in Part 3 about why this is nearly impossible to do. However, let’s assume for a moment that STEVE SMITH has a ton of computing resources and it isn’t quite nearly impossible to corrupt C anymore. Now, let’s see why the older a block is, the harder it is to corrupt.

    STEVE SMITH sees a huge transaction of cryptocurrency in block A and wants it for himself. In order to pull of his heist, he alters the transaction in block A, but now A’s “My Hash” is wrong (we’ll discuss tomorrow how the network knows it’s wrong). STEVE SMITH then spends a bit of time calculating A’s correct new My Hash. Once that’s done, there’s still a problem. B’s “Prev. Hash” is wrong, and the network will see the obvious inconsistency. STEVE SMITH changes B’s Prev. Hash to match A’s My Hash. Great! All fixed!

    But wait! B’s My Hash is calculated in part using B’s Prev. Hash, so now B’s My Hash is glaringly wrong. With a sigh of frustration, STEVE SMITH begins the time intensive process of calculating B’s new My Hash. STEVE SMITH, being one of the smartest of his race, sees that block C is going to have the same issue, so he quickly updates C’s Prev. Hash after figuring out B’s My Hash, and begins cranking on C’s My Hash. Finally, after a bit of time, STEVE SMITH has updated the blockchain and his crime was a success!!

    Or not. See, while he was cranking hard calculating new hashes for three blocks, the blockchain network was adding new blocks every few minutes (10 minutes for Bitcoin). His fraud sticks out like a sore thumb because blocks D through L all have the wrong hash when his “modified” blocks are included. In order for STEVE SMITH to succeed in his nefarious plan, he would need to control a significant portion of the entire world’s computing power, something on the order of 45% of the blockchain would need to be controlled to give his plan even a dismal chance.

    I’m going to stop here. We’re going to dive down to a place where giant octopi and fish with bioluminescent lures live in Part 3. We’ll discuss the details of how hashing is extensively used in the blockchain, how incentives are used to increase security through mining, how blockchain can be used outside of cryptocurrency, a description of the major cryptocurrencies and what they’re useful for, and some of the drawbacks of cryptocurrencies.

  • A Deep Dive into Cryptocurrencies and Their Operation: Part 1

    What this is

    An in depth perspective on how blockchain and cryptocurrencies work, along with a running commentary on social value, libertarianism, and whatever the heck fits my fancy. I’m attempting to write this at a high school comprehension level so that those who haven’t sat through 4 years of computer engineering classes can make sense of all of this.

    What this isn’t

    A primer on Bitcoin, an economic treatise, or a how-to. (Although, elements of all of those things will appear)

    For those who don’t feel like scrolling through pages and pages of my ramblings, here’s the TL;DR. Blockchain is a bunch of messages with security built into them. The security isn’t perfect, but each message is increasingly secure as time passes. The list of messages is saved on every computer that participates in the blockchain, and the lists are constantly being compared for agreement. Blockchain relies on a bit of a gambit. They essentially say “you may be able to break the security on one node, or even a few, but after a few the increased security that comes with time passing will catch up with you, and you’ll be stuck well before you come close to succeeding in fraud.”

     

    A Survey of Computer Science

    Numbers in an Array

    Computers are complex and simple at the same time. It takes millions of lines of code and tens of thousands of man-hours to put together the latest Windows or OSX version, and yet everything a computer does is simply a whole bunch of numbers saved in an array called memory.

    Let’s look at an example computer memory:

    Whaaaaaaaa??

    Let’s ignore all of the writing for a moment and discuss what we’re looking at. Memory is “byte-addressable,” which means that you can access information 8 bits (there are 8 bits in a byte; a bit is a single value of “1” or “0”) at a time. If I want to access the byte at address 0, I write some code that properly references address 0, and I have access to the value in that address of memory. If all data was 8 bits long (e.g. a number between 0 and 255), then we’d have a pretty easy go of accessing data. Just remember the order you put it in, and you just call the number that you put it in (minus 1 because the addresses start at 0).

    However, as shown in the above image, data can be much larger than 8 bits. The yellow 2-byte data is a short integer (e.g. a value between 0 and 65,535). The purple 4-byte data is an integer (e.g. a value between 0 and ~4.3 billion). There are other types of data that are even longer, like decimal numbers (called floating point numbers). Here’s more info on memory and how it works. Now it gets a bit more complicated to remember where things are in memory.

    Arrays: A Simple Way to Store Large Amounts of Data

    When dealing with simple data, like an integer, storing it in memory is relatively simple. As long as you know what address it starts at and how long that type of data is, you can access and retrieve the data. However, what are we to do when there is a bunch of related data?

    For example, what if we want to store the daily profits for the week from our monocle and top hat shop? Now we don’t have just one piece of data to deal with, but seven. We could just toss each day’s profit into memory as we encounter it, but the accounting program we’re running may store additional info in memory: temporary values, user credentials, and other information needed by the program will also reside in memory.

    We can remember each address for each individual day’s profit data, but these values are related, and it’s hard to manage access information on seven values, let alone 70 or 700 or 700,000. Treating each value individually doesn’t scale.

    As shown above, Sunday’s Profit is separated from Monday’s Profit (both in red) by intervening unrelated data (in green). In order to access the week’s profit, you need to know the address of each and every day’s profit, and you have to individually retrieve each data point.

    In comes a better way to handle such data: Arrays! Much like memory is an array with addresses referencing each byte, array data structures store related information sequentially so that each piece of information can be referenced with an array address.

    The difference is clear. The array groups the related data together, and you can simply reference the array to get to any of the data. Array address 0 is Sunday’s profit, which is located in memory addresses 0-3. Array address 1 is Monday’s Profit and is located in memory addresses 4-7. Rather than needing to remember all of the memory addresses for each day’s profit, you can simply remember the starting memory address of the array, and use the array address to calculate where each piece of information in the array is located. For example, array address 1 translates to the array starting memory address (0) plus one array element (which is 4 bytes long), resulting in a memory address of 4. If you look at the above image, array address 1 starts at memory address of 4. NOTE: I haven’t included all 7 days of profit in the above image so that it won’t get too complicated and confusing. Here is some additional information on arrays.

    However, you can also see a limitation in the above image. It works great if you know exactly how much data you need to store, but look at where the Temporary Data and User Credentials are stored. If you need to include one more piece of information in the array, you’re hosed. Either you have to start moving a bunch of stuff around in memory to make room (which is not ideal), or you have to continue the array somewhere else in memory and keep track of 2 array portions (which is also not ideal).

    Linked Lists: Good for dynamic data

    You may be wondering what the point of all of this is. We’re talking about blockchain, not about memory management, right? I promise, this is where we connect to blockchain.

    Let’s see if we can combine the best of both worlds. Writing each day’s profit to memory separately allows you to add additional days without having to shuffle data around in the memory. On the other hand, preserving the relationship between all of the days’ profits without having to keep track of each day’s memory address allows you to scale up to large amounts of data without overcomplicating things.

    One of the “best of both worlds” solutions is called a linked list. A linked list operates much like writing each day’s profit to memory separately, but preserves the relationship between the different days by including an additional bit of information pointing to the location of another day’s profit in memory.

    As you can see, we have expanded Sunday’s profit and Monday’s profit from 4 bytes to 5 bytes. The additional byte (in yellow) points to the previous node. Since Sunday’s profit is the first node, its previous node is NULL (meaning it doesn’t have a previous node). Since Monday’s profit is the second node, it points back to Sunday’s profit. Previous Node 0 points to the starting memory address of Sunday’s profit.

    Visualized another way, the linked list looks like this:

    This is the basis of blockchain. A data structure with a payload and a reference to the previous block in the chain. Now let’s talk about security.

    Hashes: Breakfast for the Masses

    I dunno about y’all, but I’m sick of reading. Let’s take a quick break before getting into hashes by enjoying some pictures

    Breakfast Hash and some red meat for the audience.

     

    Hashes: Preserving Relationships and Security

    Alright, back out of your bunks. Time for some more learnin’. Hashes are conceptually simple, but mathematically complicated. Since we’re not diving into the math, this section should be a breeze!

    No, not that kind of Brees!

    Let’s take a look at the array again:

    If we call Array[0] we get Sunday’s Profit, and if we call Array[1] we get Monday’s profit. However, we don’t always have a situation where we know exactly what order the data will be put into the array. Imagine, for a moment, that instead of 3 days of profits, we have 3 years of profits, entered manually by an employee who isn’t guaranteed to get everything perfectly in order. How do we find Monday’s Profit in that deluge of data?

    The traditional way is to search for the data in the array. Here is some more information on searching.

    The fun way is to use hashing! How about we use some relevant characteristic of the data to access the data instead of the array index (“index” is another term for array address number). All you need is two math equations: one to determine the hash from the data, and another to determine a memory location from the hash.

    As you can see, Sunday’s Profit data was hashed to “Sunday”, which is a characteristic of the data (specifically, the day of the week), and “Sunday” was computed to be connected to array address 0. Now, instead of accessing Sunday’s Profit data by loading Array[0], you can access Sunday’s Profit data by loading HashArray[“Sunday”].

    If this is a bit confusing, another simple hashing algorithm that appears in everyday life may clarify things. Placing medical records in alphabetical order by the first letter of the last name is another hashing algorithm. If the last name is SMITH, the “algorithm” for obtaining the hash involves looking at the first letter of the last name, “S”. Then, the hash “S” points to a specific shelf in the fileroom (the “S” shelf, for lack of a better name). SMITH’s folder is placed on the “S” shelf. When I want to retrieve a folder starting with “S”, I pull a folder off the “S” shelf, and I have SMITH’s folder.

    But there are many people with a last name starting with “S”. What happens when SMITH’s folder is stored on the “S” shelf and I want to store Slaver’s folder? This is called a “hash collision.” Depending on the specific situation, a hash collision is either an inevitability or a disaster. In cases where hash collisions are expected, we could simply change the data stored. Rather than just storing one piece of data for each hashed value, we can store the data for each hash in a linked list. Now, the “S” shelf looks like this (pointer is just a fancy term for the memory address):

    This is great for categorization hashes like the alphabetical sorting of medical records, but isn’t the best for cryptographic hashes like are used in blockchains. Instead, cryptographic hashes rely on another protection from hash collisions, small data density.

    Bitcoin and most other cryptocurrencies use what is called SHA-256 hashing. In SHA-256, a message of any* size is hashed using really fancy math into a 256 bit number, which means there are 2^256 possible hashes (1.1×10^77 for you scientific notation folks, or roughly 1/10 of the total number of atoms in the universe). Hash collisions are so rare under SHA-256 as to be practically nonexistent.

    *Technically, there is a maximum length of message, but it’s enormous.

    But I mentioned above that hashes are based on characteristics of the data. “S” is the first letter of SMITH, and it’s fairly easy to see the relation. What is the relation between some seemingly random 256 digit number and a Bitcoin block? Well, it has to do with math well beyond my ken, but you can go here for a bit of an explanation (as well as a look ahead). In essence, the math takes all of the data, divides it into chunks, and does a mathematical transformation on each chunk before assembling the results into the hash.

    Okay, assuming you’re following along so far, you understand how categorization hashes work and that cryptographic hashes are different, but how do cryptographic hashes work?

    Cryptographic hashes work on the principle that it’s much easier to do the math to hash the data than to derive the data from the hash. Let’s look again at the medical records example for a picture of how this works. If you’re given the last name SMITH and told that the hashing function (fancy term for the math to calculate the hash) is the first letter of the last name. It’s trivial to calculate a hash of “S” from the data “SMITH.” However, let’s go the other direction… if all I give you is “S”, you have thousands of last names to choose from. The chance of you guessing “SMITH” is extremely low.

    The same principle applies to SHA-256 hashes. It’s relatively easy for a computer to calculate the hash from the original data, but (practically) impossible to derive the original data from the hash.

    We’ll discuss the specific way cryptographic hashes are used in blockchains later on.

    Let’s take another break. Things are getting a bit intense. In the spirit of the glib baby pics from a while back, here’s me in a sombrero.

    Cultural Appropriation from a Young Age

    How about some relaxing pics from a backpacking trip I took a long time ago?

    Public Key Cryptography

    Alright, back to talking security! We’ve laid the groundwork for explaining the structure and security of the blocks in a blockchain, but let’s talk about individual currency transactions and how they’re secured. If I want to send 50 bitcoins to ZARDOZ, we create a transaction to transfer the bitcoins from my wallet to his. The details will be covered later, but it’s important to notice that without any security, STEVE SMITH could read the transaction, and use the information contained in the transaction to create a fake transaction to send the 50 bitcoins to him instead of ZARDOZ.

    What sort of security is used on these transactions? Public key cryptography! Public key cryptography uses the same concept of “one way” algorithms, just like the cryptographic hashes. In fact, in some cases, the mathematics for generating cryptographic hashes is used in public key cryptography.

    How does it work? Let’s assume I want to send a secret message to ZARDOZ. I’m sending it over the Internet, which isn’t a particularly trustworthy place. I can’t just send the text in the open. ZARDOZ decides to generate two “keys.” In this context, one of the keys is used in combination with fancy math to encrypt the message so that it can’t be read by STEVE SMITH. The other key is used in combination with more fancy math to decrypt the message. The cool thing about public key cryptography is that you can’t figure out the decrypting key by looking at the encrypting key or at an encrypted message. This is called asymmetric cryptography.

    In contrast, symmetric cryptography can be “broken” by looking at the encryption key and the encrypted message. Of course, that means you shouldn’t broadcast your symmetric encryption key on an insecure channel. For example, if my encryption algorithm is addition of the encryption key to the data, and my encryption key is 4, then if my data is the number 10, the encrypted data is the number 14 (10+4 = 14). I send 14 across the unsecured network to ZARDOZ, who uses the symmetric decryption key (the number 4), and the decryption algorithm of subtraction of the decryption key from the data, and ZARDOZ gets the original data, the number 10 (14 – 4 = 10).

    Seems secure enough, especially when we use something more complicated than “add 4” as an encryption. But why are we talking about asymmetric cryptography instead? Well, because we have a problem. The Internet isn’t particularly secure, and we’re not gonna VPN with the entire bitcoin network, most of whom we don’t trust, to send them our secret key. With asymmetric cryptography, the encryption key (called the public key) can be known by everybody. It doesn’t matter if half the world can encrypt messages intended for you. As long as they’re not able to decrypt those encrypted messages, the system is secure. That’s why the decryption key is called the private key. The private key must be kept secret by the receiver of the message.

     

    As shown above, I have sent ZARDOZ the message “Molon Labe!” ZARDOZ has vomited forth (published) his public key, which allowed me to encrypt my message and send it across the Internet securely. As you can see, STEVE SMITH can try his hardest to intercept my message to ZARDOZ, but all he gets is a bunch of gibberish. Then, once ZARDOZ receives the encrypted message, he uses his private decryption key (secreted away in the Vortex where nobody can access it except ZARDOZ) to decrypt the message and read “Molon Labe!”

    Now, this is great and all, but isn’t blockchain about publicly accessible data and verification instead? Well, yes. Let’s take this public key encryption and flip it around. Now, instead of keeping the data secret, we want to make sure the data is from the right person. I’m expecting a message from ZARDOZ, and want to make sure that it’s legitimately from ZARDOZ and not from STEVE SMITH.

    As you can see, the message stays public the entire time, but there is extra data added based on ZARDOZ’s private key. This is called a signature. Upon receipt, anybody can verify the authorship of the message by using the public key.

    What happens when STEVE SMITH tries to meddle again?

    As you can see, STEVE SMITH, in his ham fisted way, has altered the message before I have received it. When I try to verify the message’s authorship, I find out that it’s not from ZARDOZ, and thus it’s a suspect message to be ignored.

    This is the basis for verifying cryptocurrency transactions. We’ll put all of this book learning together into a workable model in the next article or two, but this article explains most of the theoretical underpinnings of blockchain and cryptocurrencies.