An intro to Cryptography + Bcrypt

Encryption

For most of history, cryptography consisted of encrypting messages with a substitution, permutation, or columnar transposition cipher. Essentially these ciphers transposed one letter into another letter, and you needed a key to encrypt and decrypt. This worked very well until cryptographers and mathematicians became increasingly adept, and could begin to decrypt these messages using statistics, based on the frequency of letters. The next most complex was the German Enigma cipher which utilized much more complex mechanisms to encrypt messages, including dynamic keys. It took much more effort to discover the key for this!

Hashing

Hashing is clearly described as a method of one way encryption. Plaintext is inputted, and a hash is outputted. You cannot go back from a one way hash without the original string. Complex mathematical functions ensures this stays true.

Bcrypt

Bcrypt is a “slow” hashing algorithm used within Ruby on Rails to securely encrypt data. If our passwords were stored within the database in plaintext, then anybody would be able to see our passwords if the database was compromised. This is why passwords and other sensitive data must be encrypted before entering the database. Bcrypt uses a one way function to encrypt your data, so with an input of“flatiron”, Bcrypt generates a complex output as the result. It is much easier to go in this one direction than the reverse since it is a one way function. These get pretty complex, so I will add some resources below to dive a little deeper. Below, I will go into some of the logic behind Bcrypt, and benefits over other hashing algorithms. I hope to give some insight on why Bcrypt works as it does.

Photo by Bermix Studio on Unsplash

Other Hashing Algorithms/ Cryptocurrencies

Some other hashing algorithms include SHA1, SHA256, SHA512 and SCRYPT. The SHA are fast hashes, which are bad for passwords as hackers can brute force these much quicker than the slow SCRYPT and BCRYPT.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store