Anyone with an interest in bitcoin will have heard the phrase 'cryptographic hash function' at some time or other. But what exactly does it mean, and how is it connected to cryptocurrency?
Hash functions are an essential part of, not only of the bitcoin protocol, but of information security as a whole.
In the following article we'll take a look at some simple examples of how they work, with a simple demonstration, too.
In the abstract, a hash function is a mathematical processthat takes input data of any size, performs an operation on it, and returns output data of a fixed size.
In a more concrete example, this can be used to take a sequence of letters of any length as input what we call a string and return a sequence of letters of a fixed length. Whether the input string is a single letter, a word, a sentence, or an entire novel, the output called the digest will always be the same length.
Acommon use of this kind of hash function is to store passwords.
When you create a user account with any web service which requires a password, the password isrun through a hash function, and the hash digest of the message is stored. When you type in your password to log in, the same hash function is run on the word you've entered, and the server checks whether the result matches the stored digest.
This means that if a hacker is able to access the database containing the stored hashes, they will not be able to immediately compromise all user accounts because there is no easy way to find the password which producedany given hash.
You can experiment with hash values using Python, a programming language installed on Mac and Linux operating systems by default. (This tutorial will assume you're using some version of either OS X or Linux, as using Python on Windows is more complicated.)
First, open a terminal, type python and hit ENTER.
This will put you into the Python REPL, an environment where you can try out Python commands directly as opposed to writing a programme in a separate file.
Then, type the following, pressing ENTER after each line, and TAB where marked:
You have now created a function, hash(), which will calculate and print out the hash value for a given string using the MD5 hashing algorithm. To run it, put a string in between the parentheses in quotation marks, eg:
And press ENTER to see the hash digest of that string.
You will see that calling the hash function on the same string will always generate the same hash, but adding or changing one character will generate a completely different hash value:
In the bitcoin protocol, hash functions are part of the block hashing algorithm which is used to write new transactions into the blockchain through the mining process.
In bitcoin mining, the inputs for the function are all of the most recent, not-yet-confirmed transactions (along with some additional inputs relating to the timestamp and a reference to the previous block).
In the code example above, we've already seen that changing a small part of the input for a hash function results in a completely different output. This property is crucial to the 'proof of work' algorithm involved in mining: to successfully 'solve' a block, miners try to combine all of the inputs with their own arbitrary piece of input data in such a way that the resulting hash starts with a certain number of zeroes.
As a basic demonstration, we could try 'mining' with our Python hash function by manually adding exclamation points after "CoinDesk rocks!" until we find a hash that starts with a single zero.
Of course, solving the hash for a bitcoin block which at the time of writing must start with 18 zeros requires anextremely large amount of computation (and so the combined processing power of all the computers in the network still takes approximately 10 minutes to solve a block).
It's the need for this large amount of processing power that means new bitcoins get mined over a long period of time, not all at once.
In order to earn bitcoins through mining, you need to put in the huge amount of work necessary to solve a block and by earning that reward, you're locking in all of the new transactions into a block, which is added to the permanent record of all previous transactions: the blockchain.
Any crypto basics you'd like explained next? Email: editors@coindesk.com.
Bitcoin on keyboard image via Shutterstock
Bitcoin ProtocolCryptographyhash functions
See the original post:
Bitcoin Hash Functions Explained - CoinDesk
- Chinas Bitcoin Exchanges Say Banks Will Close Their Accounts [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- How I created my own bitcoin [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- How I created my own bitcoin-like currency [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Bitcoin players knock on Washington doors [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- How does Bitcoin work? - Bitcoin [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Should We Do a Bitcoin Sketch? - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Bitcoin Talk Show #4 with Chris Ellis and Thomas Hunt - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Bitcoin - an Introduction - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Bitcoin ATM Unveiled on Capitol Hill - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Fla. Bitcoin Case Tests Money Laundering Limits - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Capitol Hill Bitcoin ATM...No Anonymity! April 10 2014 - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- BREAKING: US Congressman Steve Stockman To Introduce First Bitcoin Bill - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- 10 Things You Didn't Know About BitCoin - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- All about Bitcoin - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Internet vs Bitcoin - Video [Last Updated On: April 11th, 2014] [Originally Added On: April 11th, 2014]
- Bitcoin: The Future of Currency? - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Watching Bitcoin dropping to new lows - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Bitcoin ATM unveiled in Washington DC: revolutionary digital currency arrives on Capitol Hill - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Qu'est-ce que le bitcoin ? - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Decentralize Everything -- Congresswoman Velazquez supports Bitcoin -- Stallman in Vienna - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Drake Bitcoin's Here Music Video - Bitcoin T Shirt Store - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- China tightens leash on bitcoin - Biz Wire - April 4,2014 - BONTV China - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- What is BITCOIN? Andreas Antonopoulos & Amir Taaki explain BTC value - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Texas Bitcoin Conference - Robocoin & Coinvault ATM - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Texas Bitcoin Conference - BitShares - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Is Bitcoin the Future of Money? (with Timothy B. Lee) - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Robert Murphy at Texas Bitcoin Conference 2014 about Austrian Economics, money theory and Bitcoin - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- CryptexCard - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Father of Virtual Reality on Bitcoin April 8 2014 - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- California's first bitcoin ATM launches in Silicon Valley - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Bitcoin Fight Night: Kickboxing for bitcoin and Max Keiser 'defeats banksters' - Video [Last Updated On: April 12th, 2014] [Originally Added On: April 12th, 2014]
- Bitcoin blunder: Satoshi Nakamoto denies all involvement with cryptocurrency [Last Updated On: April 13th, 2014] [Originally Added On: April 13th, 2014]
- Bitcoin gets easier for consumers to buy, spend [Last Updated On: April 13th, 2014] [Originally Added On: April 13th, 2014]
- 11.04.14 Forex, Bitcoin Romanov Capital - Video [Last Updated On: April 13th, 2014] [Originally Added On: April 13th, 2014]
- USA: Capitol Hill gets its own Bitcoin ATM - Video [Last Updated On: April 13th, 2014] [Originally Added On: April 13th, 2014]
- Bitcoin, a moeda virtual. - Video [Last Updated On: April 13th, 2014] [Originally Added On: April 13th, 2014]
- Bitcoin creator Satoshi Nakamoto tracked down, but says story has no currency [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Bitcoin's backers know they need to win you over [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- [Structure] Heartbleed and Bitcoin - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- BitCoin mining frame - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Where Do You Think US Bitcoin Regulations Are Headed? - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Dwyer 4-11-14 Bitcoin Update - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- 4/10/14 - China & BTC, Bitcoin Tax Solutions, Libra, BitInvest Coincards - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Ben Lawsky & NY Regulators on Bitcoin - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Bill to Change IRS Ruling on Bitcoin - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Bitcoin is not over! Bitcoin Indian Food Night Saturday! (adult language, parody and yelling) - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- Demonstrating a Bitcoin ATM at Dig South - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- 10 Things You Didn t Know About BitCoin - Video [Last Updated On: April 14th, 2014] [Originally Added On: April 14th, 2014]
- How Bitcoin Works in 5 Minutes - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Bitcoin Below $400, Massive Security Breach, 4,000 Merchants, and Congress - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Reddit Co-founder Alexis Ohanian talks Bitcoin security, Mt. Gox on Joe Rogan Experience - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Cointools: Drupal & Bitcoin == $awesome - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Bitcoin ATM, Black Star Pastry, Rosebery, Sydney, Australia (Vending machine, BTM) - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- My Bitcoin Call to Alex Jones Infowars Digital Paper Wallets Storage - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- The Bitcoin Group #25 (Live) -- Bitcoin Sports -- Gox Buyout? -- Sidechains -- Dogecoin Merged? - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- 4/11/14 - China, Mt. Gox buyout, Gyft Cloud, BIT, new bitcoin symbol - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- 9 Year Old Explains Bitcoin - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- CITP Bitcoin Panel 2 Altcoins - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Why US Regulators Should Go Easy on Bitcoin - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- In Crypto We Trust Hackathon Pitches - Bitcoin Expo 2014 - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- CITP Bitcoin - Panel 1: Economics and Public Policy - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- David Chen of Lightspeed Ventures visits Plug and Play Bitcoin - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Video: Roundup of This Week's Bitcoin News 11th April 2014 - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Peace and Bitcoin Remastered - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- [Bitcoin] Cannot be divorced from pre-existing political theory - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Bitcoin Trade 114 - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Wall Street's Fair Value of Bitcoin - Inside Bitcoins NYC 2014 - Video [Last Updated On: April 15th, 2014] [Originally Added On: April 15th, 2014]
- Elliotte Wave Technical Analysis Applied to Bitcoin - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Bitcoin Wisdom Depth Chart - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Live - Paris Bitcoin Startup #2 @TheFamily - Mercredi 16/04/2014 ds 19h - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Not Tax Day, Bitcoin Day! - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Preview: The Bitcoin Uprising - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- WCN Live: iNacho -- an interview with Jerica Truax -- win a bitcoin by rating Nachos! 🙂 - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Can You Use Bitcoin for a Tax Haven? - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- What Is Proof Of Stake In Nextcoin (NXT) vs. Proof Of Work In Bitcoin (BTC) - By Tai Zen - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Bitcoin, little failures and huge successes - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Dutch Ethereum & Bitcoin Meetup: Coin Unlimited over Bitcoin en altcoins - Edwin van den Ouden - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Dutch Ethereum & Bitcoin Meetup: Tor (The Onion Router) Joachim de Koning - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Dutch Ethereum & Bitcoin Meetup: First Steps in Ethereum - Joachim de Koning (part one) - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]
- Dutch Ethereum & Bitcoin Meetup: First Steps in Ethereum Joachim de Koning (part two) - Video [Last Updated On: April 17th, 2014] [Originally Added On: April 17th, 2014]