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:
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) as its input, and outputs theencrypted text
. 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) as its input, and outputs theplaintext
. 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
() to work correctly. If we want to revise the above representation,
here would be the updated and more accurate generalization.
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:
- say 5 is our plaintext.
- Encryption: We shift if by 3 (secret key),
- and reach 8 (ciphertext).
- The other party we are trying to communicate also knows the secret key (3),
- Decryption: When we send her our ciphertext (8), she can shift 8 in the reverse direction to decipher,
- and reach the plaintext (5).
- 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:
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.