Video Coming Soon...

Created by Zed A. Shaw Updated 2026-11-26 20:48:52
 

49: sha2sum

WARNING: This is from the Go course but I'm rewriting the code and the description to fit C. If you want to attempt it go ahead. The challenge is the same, just no examples yet.

There's many different hashing utilities, but they all do the same thing: convert a gigantic number to a smaller number using cryptographic primitives. The one you'll use is called sha512 and Go provides very good cryptography support in the standard library.

The way a tool like sh2sum works is this:

  1. It opens a file and reads in the bytes.
  2. Each byte is also a number, so it can feed that byte to a cryptographic function.
  3. This function's design allows it to input many, many numbers but only output one large number. In our case, a 512 bit number.
  4. These functions are required to have "no collisions," which means if you feed them even slightly different inputs you should get totally different results.
  5. This lets you sha2sum a file to confirm that you received the right one, that it wasn't corrupted, and to just know if two files are actually different.
Previous Lesson Next Lesson

Register for From Impostor to Programmer

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.