Symmetric Key Cryptography

What is it good for?

This is the most naïve approach towards encryption. Using symmetric keys, we can encrypt/decrypt a message. In this approach, both parties need to have the same key, and distribution of these keys is the problematic part (assume both parties cannot meet physically, in this case, they need to announce their keys in plaintext first, for which, an eavesdropper can listen and learn the key).

On the other hand, it is simpler, faster, and more efficient than public-key cryptography. So, it is a good approach to first do the key distribution with public-key cryptography, then apply symmetric key cryptography for communication.


How it works?

There are many algorithms for implementing symmetric key cryptography. However, all of them can be generalized into this:

encryptionf(x)=yencryption \rightarrow f(x) = y decryptionf1(y)=xdecryption \rightarrow f^{-1}(y) = x

The above equations are the generalized versions of encryption and decryption for nearly every symmetric key cryptography protocol. Here is a more detailed explanation of what is going on behind the scenes:

  • Encryption is a function. It takes the plaintext (message to be encrypted) xx as its input, and outputs the encrypted text yy. Implementation and details of this function will vary for different symmetric key cryptography algorithms (i.e., AES, DES, etc.).
  • Decryption is also a function, but it is the reverse of encryption. It takes the ciphertext (encrypted text) yy as its input, and outputs the plaintext xx. Again, the implementation will vary for different symmetric key cryptography algorithms (i.e., AES, DES, etc.)

In other words, think of these functions as black-boxes, they take an input, and spit out an output (just like you, consuming food, producing poop). However, these black-boxes are the inverses of each other (the reverse of you, would be the plants in this metaphor, consuming poop, producing food).

Unfortunately, the above representation is not 100% accurate, since both of the encryption and decryption functions will need the secret key (ss) to work correctly. If we want to revise the above representation, here would be the updated and more accurate generalization.

encryptionf(x,s)=yencryption \rightarrow f(x, s) = y decryptionf1(y,s)=xdecryption \rightarrow f^{-1}(y,s) = x

An Example

For demonstration purposes, we will be implementing a very basic algorithm, Caesar Cipher, which is very easy to crack, thus not secure!

Use Caesar Cipher only for educational or fun purposes!

Caesar Cipher is also known as the shift cipher, it shifts the plaintext by some amount, and this amount will be the secret key.

For example:

  1. say 5 is our plaintext.
  2. Encryption: We shift if by 3 (secret key),
  3. and reach 8 (ciphertext).
  4. The other party we are trying to communicate also knows the secret key (3),
  5. Decryption: When we send her our ciphertext (8), she can shift 8 in the reverse direction to decipher,
  6. and reach the plaintext (5).
  7. Notice that, anybody who does not the value of secret key (3) will have a hard time deciphering the ciphertext (8) into plaintext (5).

Let us define our functions more concretely for Caesar Cipher:

encryptionf(x,s)=x+s=yencryption \rightarrow f(x, s) = x+s = y decryptionf1(y,s)=ys=xdecryption \rightarrow f^{-1}(y,s) = y-s =x

Bonus

Are you wondering how can we apply Caesar Cipher to letters? First, we should convert letters to numbers, for this, the convention is to follow ASCII table (http://www.asciitable.com). We can convert any symbol to numbers using ASCII table, and then apply our cryptographic algorithm to these numbers.