Security

Introduction to Cryptography

Does the word cryptography sound cryptic? Read on to learn about cryptography and remove the mystery

Photo by Georg Bommeli on Unsplash

The word Cryptography is derived from the Greek words Kryptos and Graphy. Kryptos means hidden and Graphy means writing. Thus Cryptography means hidden writing.

Cryptography:

the science or study of the techniques of secret writing, especially code and cipher systems, methods, and the like

Dictionary.com

This post is an introduction to cryptography. The aim of this post is for all audiences to understand what Cryptography is. We will first look into the origins of Cryptography. Then we will cover Cryptography terminology. Finally I will explain how modern Cryptography works.

You don’t need any skills to consume this post.

The origins

The first form of cryptography recorded–that is sending a secret message–was first recorded around 100BC. The method to hide a message was by shifting each letter in the message by a specific number of letters in the alphabet. For example by shifting the letter A by 3 places to right the letter becomes D.

But why hide the message? A message can be intercepted between the sender and recipient.

hidding messages using ROT3 cipher

Cryptography terminology

Encryption:

The process of encoding a message so that it can be read only by the sender and the intended recipient.

Dictionary.com

The process of transforming the original message into a hidden message is called encryption. The original messge is referred to as plaintext. The method of hiding the message is called cipher. In the previous example moving the letter of the alphabet by 3 is known as the ROT3 cipher. And the hidden message is called ciphertext.

Encryption using ROT3

Modern Cryptography

In The Origins section we learnt the need for cryptography to hide a message. We saw that the letters were substituted for others in the alphabet by shifting specific number of letters in the alphabet i.e. 3. In order to decipher the text the inverse must be applied to the ciphertext to get the plaintext. Notice that both parties in communication must be aware of the cipher. This is referred to as shared secret. A cipher that is used to encrypt and decrypt a message is known as symmetric key.

Symmetric Key

Symmetric Key:

symmetric key is one that is used both to encrypt and decrypt information

Thales

Modern electronic communications still use the same principal of shifting using a shared secret or symmetric key. However modern cryptography introduces combinations of shifts and on different formats; for example binary format.

But how do two parties communicating with each other only over the internet share a secret without leaking such a secret? A leak of shared secret would render the communication insecure.

Asymmetric key

Asymmetric keys are used to communicate shared secrets. They come in pairs. One key can encrypt the message and the other can decrypt. However the same key can not encrypt and decrypt the message. These related keys are referred to as a pair.

Let’s look at an example. Let’s say you generate a pair of asymmetric keys named KeyA and KeyB. Messages encrypted with KeyA can be decrypted by KeyB. Messages encrypted by KeyB can be decrypted by KeyA.

Asymmetric keys used to send the symmetric key as a message

Usually a key is distributed openly and called the public key. This key is accessible to anyone. There are mechanisms using trusted third parties–most commonly known as Certificate Authorities–to check that the public key genuinely belongs to the entity you are trying to communicate with. However we are not going to delve into that in this post. For this post assume you can access the public key of the entity you are trying to communicate and you are certain that the public key belongs to them.

Using their public key you can encrypt the symmetric key to be used during following communications.

Symmetric vs Asymmetric key

If asymmetric keys can only be decrypted using the paired key then why not use asymmetric keys for all communications between two parties? Because they requires more computations and thus are slower. Asymmetric keys were created to compliment symmetric keys in establishing secure communication.

Final Notes

The art of hiding messages is very old. There are great stories on cryptography in history. My favourite story on cryptography is Enigma. Enigma was an encryption device used by the Germans during World War 2. The encryption was broken by the allies thanks to Alan Turing–who is considered as the father of modern computer science. There is film on Enigma which I recommend watching.

In the future I’ll be posting some how-to posts on securing communications in iOS and other platforms.

For more on iOS and software development follow me on Twitter or Medium!

Senior iOS Engineer @ Onfido. Writing weekly blogs on iOS and programming. Follow me to stay tuned!

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