crc snippets

Pigeonhole principle

Tagged crc, sha256, cryptography, hash, md5  Languages 

When working with hashing functions and cryptography the pigeonhole principle is essential knowledge:

In mathematics, the pigeonhole principle states that if n items are put into m containers, with n > m, then at least one container must contain more than one item.

For example, given that the population of London is greater than the maximum number of hairs that can be present on a human’s head, then the pigeonhole principle requires that there must be at least two people in London who have the same number of hairs on their heads.

This means that in order to create a completely collision-free hashing function, every message would have to have a hashed output of the same length as the input.

Converting a string to a number with CRC

Tagged conversion, crc, number, string  Languages ruby

CRC can be used to convert a string into a number:

require 'zlib'
integer = Zlib.crc32('snippet')
=> 2518453461
=> 2656977832

The CRC algorithm is normally used to detect changes or errors in large chunks of data.