Understand the crypto trio: Encode, Encrypt, and Hash
Encoding
It does not change the data and has no encryption effect. It simply represents the data in another form. A classic example is
Morse code.
- JavaScript has two useful functions:
encodeURIanddecodeURI, which encode special characters in URLs (spaces, punctuation, etc.) into URL-safe formats.Base64encodes binary data into ASCII characters.Huffman Codingis a lossless compression encoding algorithm. In short, it compresses by abbreviating frequently used symbols.
Encryption
Encryption and decryption require a key. In the simplest Caesar cipher, each letter is shifted by an offset, and that offset is the key for encryption/decryption.
- AES (Advanced Encryption Standard) is a symmetric algorithm, meaning encryption and decryption use the same key. Unlike the Caesar cipher’s 0-25 key range, AES has more than 10^38 possible keys.
- RSA is an asymmetric algorithm that uses a public key and a private key. Data encrypted with the public key can only be decrypted with the private key.
Hashing
Hashing means running each field/character through a formula to produce a value or string. The formula is a hash function. The process may involve operations like addition, subtraction, multiplication, and division. Because you cannot reverse the output to get the original input, hashing is irreversible.
