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 here:
Bitcoin Hash Functions Explained - CoinDesk
- Google removes malware Android apps used to secretly mine bitcoin [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin exchange MtGox liquidated [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin Wannabe Litecoin Emerges as Low-Price Challenger [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- The Worlds First Bitcoin Debit Card Is Almost Here [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- How does Bitcoin work? - Bitcoin - Open source P2P money [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin - Wikipedia, the free encyclopedia [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- The Bitcoin Group #27 - China Bans Bitcoin Again - Politics - Dark Market - Bitcoin VC - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Edan Yago - Free Market Bitcoin regulation and Honduras free trade zones.mp4 - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin vs. Political Power: The Cryptocurrency Revolution - Stefan Molyneux at TNW Conference - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Video: Roundup of This Week's Bitcoin News 25th April 2014 - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin Fredagsbar med Torben Mark Pedersen - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin and the Internet of Money - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin for Dummies - Video [Last Updated On: April 26th, 2014] [Originally Added On: April 26th, 2014]
- Bitcoin runner-up Litecoin emerges as low-price challenger [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- Bitcoin or Gold? Squawk Walk Taipei- Squawkonomics - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- Bitcoin Miner AntMiner S1 180 - 200 GH/s Nu in de Aanbieding! - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- New Bitcoin Documentary: Boom or Bust - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- Bitcoin May v0.9.1 GitHub Source Code Development Visualization - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- Atomic-Trade Bitcoin Exchange. AML, BSA, FinCEN compliant - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- China Bans Bitcoin Again -- Bitcoin the Movie -- Startup for Startups Raises 2,000 BTC - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- 4/24/14 - Xapo Debit Card, Russia's 1st Bitcoin Conference, Silk Road 2.0 - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- What is Bitcoin? - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- David Andolfatto, How Does Bitcoin Work? - Video [Last Updated On: April 27th, 2014] [Originally Added On: April 27th, 2014]
- Australian Bitcoin traders hit by crash [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- Bitcoin traders hit by Mt.Gox crash [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- Market Extra: Bitcoin venture capital money hasnt kept up with buzz [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- Bitcoin price slips as China steps up regulation [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- Bitcoin price slips on China regulation [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- Win .33 Bitcoin ($150 or so, Depending on BTC value) - Meme game for May 1st - Take My Bitcoins - Video [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- Ron Paul on Bitcoin - Video [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- btc.sx Bitcoin derivatives platform George Samman clip - Video [Last Updated On: April 28th, 2014] [Originally Added On: April 28th, 2014]
- 'The Rise And Rise Of Bitcoin' Filmmaker: 'There Is No Answer Yet' [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- Bitcoin the movie: It just had to happen [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- Bitcoin Vies with New Cryptocurrencies as Coin of the Cyber Realm [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- The Bitcoin Meetup - BitcoinMKE Hosts Jeffrey Tucker - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- MIT Bitcoin Expo 2014 - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- Bitcoin Expo 2014: Fireside Chat with Dr Gavin Wood - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- Rise Bitcoin Singapore - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- Preview: Bitcoin Authenticator - 2FA for wallets - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- The Bitcoin Group #27 (Live) - China Bans Bitcoin Again - Politics - Dark Market - Bitcoin VC - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- 4/25/14 - More China uncertainty, Missourian bitcoin warning, BadLepricon malware - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- Money & Tech at The Rise And Rise Of Bitcoin Afterparty - Video [Last Updated On: April 29th, 2014] [Originally Added On: April 29th, 2014]
- New Bitcoin student club at MIT will promote the virtual currency [Last Updated On: April 30th, 2014] [Originally Added On: April 30th, 2014]
- 4/29/14 - MIT Bitcoin Project, Mt Gox revival plan, Mastercard lobbyists & Team Rubicon - Video [Last Updated On: April 30th, 2014] [Originally Added On: April 30th, 2014]
- BitCoin Dentist GoCoin Fox News Interview - Video [Last Updated On: April 30th, 2014] [Originally Added On: April 30th, 2014]
- Bitcoin Foundation Election Hiccups -- Pathetic Ohio Bans Bitcoins -- Dogecon SF 2014 - Video [Last Updated On: April 30th, 2014] [Originally Added On: April 30th, 2014]
- Bitcoin Slips to $420 as BTC China Halts Transactions - Video [Last Updated On: April 30th, 2014] [Originally Added On: April 30th, 2014]
- MultiSig Plus BitCoin Multi Coin Wallet looks like HUGE INVESTMENT potential! - Video [Last Updated On: April 30th, 2014] [Originally Added On: April 30th, 2014]
- Bitcoin: what happens when the miners pack up their gear? [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Dark Wallet Is About to Make Bitcoin Money Laundering Easier Than Ever [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Bitcoin Talk Show #7 -- Skype BitcoinTalkShow to Call in Live! 🙂 - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Basic Bitcoin Bitches - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Gold standard vs Fiat vs Bitcoin - Truthloader - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- How to Defund the System: Bitcoin vs. the Central Banksters - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Bitcoin, Anarchy and Freedom with Roger Ver - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- MIT Goes Bitcoin-Wild [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Bitcoin Weekly 2014 April 30: Bloomberg adds Bitcoin to their market index, MIT to produce campus-wide bitcoin ... [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- 'Dark Wallet' wants to make Bitcoin even harder to trace [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Bitcoin made simple (video animation) - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Jon Matonis: Bitcoin - The future of commerce? - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- $100 in Bitcoin Going to Every MIT Undergrad - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- The Rise of Digital Currency - Video [Last Updated On: May 1st, 2014] [Originally Added On: May 1st, 2014]
- Money Goes Virtual: The Bitcoin Bourse - Video [Last Updated On: May 2nd, 2014] [Originally Added On: May 2nd, 2014]
- Bitcoin Lights with LIFX - Video [Last Updated On: May 2nd, 2014] [Originally Added On: May 2nd, 2014]
- Bitcoin: How We Got Here and Where We Are Going [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- 5/1/14 - Larry Summers warns critics, Paym system & Bitcoin Center NYC roundtable - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- On est Connect S2 #07 1/2 : BitCoin et Musique sur Internet - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- MIT Undergrads To Receive $100 Worth Of Bitcoin This Fall - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- Why it only took ME less than 2 minutes to believe in Bitcoin - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- Bitcoin Basics and Regulation Thoughts from NH Liberty Forum - Bruce Fenton - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- PRIMER CAJERO DE BITCOIN EN BIT CENTER DE TIJUANA - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- Yelp adds Bitcoin acceptance to business listings - Video [Last Updated On: May 3rd, 2014] [Originally Added On: May 3rd, 2014]
- Bitcoin A Terrorist Threat? Counterterrorism Program Names Virtual Currencies As Area Of Interest [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- How Does Bitcoin Works - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- 10 Things You Didn't Know About BitCoin - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- BITCOIN The Future of Money - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- Bitcoin Miner Review - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- The Bitcoin Group #28 (Live) - Yelp Lists Bitcoin - MIT Bitcoin $100 - Dark Wallet - Ohio Bans BTC - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- Bitcoin: Gary North is Mentally Deranged And Bitcoin Will Change Everything - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]
- Who is the Bitcoin Warlord? - Video [Last Updated On: May 4th, 2014] [Originally Added On: May 4th, 2014]