Submit an Entry

To enter the challenge, you need to signup or login.

This Challenge's Best Entries [View All]

(View the Overall | Perl | PHP | Python | Ruby leaderboard.)

Rank User Size Language Score [?]
1st flagitious 338 Ruby 10,000 (v35)
2nd jojo 386 Ruby 8,756 (v59)
3rd ksk 388 Ruby 8,711 (v5)
4th mtve 396 Perl 8,535 (v13)
5th shinh 420 Ruby 8,047 (v22)
6th mame 436 Ruby 7,752 (v10)
7th carldr 437 Ruby 7,734 (v31)
8th kik 447 Ruby 7,561 (v4)
9th ySas 452 Perl 7,477 (v53)
10th irori 461 Ruby 7,331 (v16)

See who is active in this challenge →

SHA-256 Hashing

(Challenge added 1305 days ago.)

Implement the SHA-256 Hashing Algorithm.

Discuss This Challenge →

The Problem

Hash functions are widely used to generate small fingerprints of all kinds of data and are generally used in authentication schemes and for verifying data. MD5 and SHA-1 are currently the most commonly used hashing functions, but it would be boring to ask you to implement one of those. So, we're going for SHA-1's big brother, SHA-256.

SHA-256 works by taking arbitrary data (of maximum length 2EiB) as its input and producing, through various calculations, a 32-byte hash of that data (64 characters when represented in hex.)

I won't be able to give a better explanation of the algorithm than Wikipedia's SHA-256 entry, so I won't even try. (You'll be pleased to know that that page includes pseudocode for the algorithm which should allow you a working version fairly quickly.)

In addition, the information in the FIPS 180-2 document (PDF) may be useful since it gives worked examples (Will be useful for debugging) and is more detailed than the Wikipedia entry.

More Information

  • Your code will be run five times, and on each run be given data on stdin and be expected to print the hexidecimal digest of that data on stdout.
  • To make testing easier, that data will be ASCII text. Note that none of the text has trailing newlines at the end-of-file (although newlines in the text itself are significant.)

Examples

The data for the first 4 runs of your code will have the same input :

The fifth and final run will be a randomised set of 28 words. To get a random sample, click below. Reload the page to get a new sample.