Cryptography and its uses

Cryptography and its uses

Written By: Akinola Ayomide
Edited and reviewed by: Owolabi Olutola

In 50BC, the roman emperor Julius Ceaser wanted to send secret messages to his generals during the Gallic war. To do that, he converted the plaintext messages to unreadable texts using a process known as cryptography.

Cryptography is coined from the greek word "Krypto" meaning hidden, and "-graphy" meaning writing. It is the study of secret communication using a series of encryption and decryption processes. Encryption is the convertion of human readable data to unreadable data (Ciphertext), while decryption is the conversion of these encrypted data(Ciphertext) to readable data (plaintext).

In this article, we will explore,

  • How cryptography works

  • Role of cryptography in Blockchain, and

  • Other uses of cryptography

How cryptography works

Cryptography makes use of mathematical techniques for secret transmission of private messages usually through an insecure medium. These techniques aim to provide confidentiality, authenticity, and integrity to the message being transmitted.

It achieve confidentiality by converting the plaintext to unreadable text (ciphertext) using encryption algorithms, conserve integrity by using hashing techniques, and authentication using secret keys only known to the communicating parties. These encryption algorithms are of two types:

  • Symmetric encryption

  • Asymmetric encryption

Symmetric encryption

Symmetric encryption involves the use of a single secret key to encrypt and decrypt data. For this to work, both the sender and reciever must share the same key. An example of symmetric encryption is the Ceaser Cipher. In Ceaser Cipher, the letters D to Z are encrypted by letters that comes three times latter that them in the alphabet. While the remaining letters A, B, and C are represented by X, Y, and Z respectively. Here, the secret key is the shift key - "3". For example

Plaintext - "You can now attack"

Ciphertext - "Vlr zxk klt xqqxzh"

This encryption can be cracked because the shift key can easily be determined. Overtime, more secure encryption was developed using advanced mathematic calculations such as permutation, transposition and so on. Other examples of symmetric encryptions are Block Cipher, Steam cipher, and one-time pad cipher. In symmetric encryption, the secret key for encrypting and decrypting data needs to be distributed between the communicating parties. Distributing this secret key securely can be difficult and sometimes involves the establishment of a third party key distribution center.

Asymmetric encryption

This encryption method evolved to solve the key distribution problem in symmetric encryption. Asymmetric encryption make use of two keys, a public key and a private key in the encryption and decryption processes. The public key is freely distributed and it is mathematically derived from the private key. The public key is derived in such a way that it is impossible to reverse engineer it to get the private key.

The private key is used to encrypt the data, which can only be decrypted using the public key. This can also happen interchangably, where the public key is used for encryption and the private key is used for decryption. An example of asymmetric encryption is the Rivest-Shamir-Adleman (RSA) scheme which uses computational factorization together with the public and private key concept to encrypt and decrypt data. Another example is Elliptic Curve Cryptography (ECC) which uses algebric structure of elliptic curves over finite fields, as its computational approach.

Role of cryptography in Blockchain

In blockchain, data are encrypted and grouped into blocks. Blocks are linked through cryptographic hash, hence producing a chain of blocks. Except the first (genesis) block, the linkage of every sucessive block helps to strenghten the authenticity of the preceeding blocks.

Asymmetric encryption is used to generate public and private keys for accounts on blockchain. Bitcoin and Ethereum use the Elliptic Curve Cryptography (ECC). First, a random 256 bit ramdom number is generated. This random number becomes the private key. Then, the encryption algorithm is applied to the private key to generate the public key. This algorithm uses prime number factorization principle which state that, no matter how large a number is, it can be produced by multiplying prime numbers. It is easy to produce a number by multiplying prime numbers but it is very hard to reverse the process. Blockchain relies on this concept to ensure that a public key cannot be reverse engineered to give the private key.

Other uses of cryptography

Cryptography is used in secured wireless communication systems such as Bluetooth and WiFi. Bluetooth uses a symmetric encryption - steam ciphers E0 to encrypt its payload.

Hypertext Transfer Protocol Secure (HTTPS) uses both symmetric and asymmetric encryption to securely transmited data between a web browser and a web server. Let's assume the web browser is the King of France and the web server is the King of Spain.

The king of Spain wants to securely send a large box containing Gold to the king of France. So, the king locked the large box with a special key. He then placed this special key into a small box, which he also locked using a smartlock whose passcode is only known to the king of France. He then sent both large and small boxes to France. For the king of France to access the Gold, he first opened the small box using his secret passcode, then got the special key out of the smaller box, and used it to open up the large box containing the Gold.

  • The **Gold **is the **data **being sent from the web server to the web browser.

  • The special key is a random symmetric private key generated by the web server.

  • The locked large box, is the encrypted data using the private key on the web server.

  • The smartlock used to lock the small box is the public key of the web browser.

  • The locked small box is the encrypted random private key of the web server using the public key of the web browser.

  • The secret passcode is the private key of the web browser.

In summary a random private key on the web server is used to encrypt the data, then the random private key is encrypted using the public key of the web browser. The two encrypted data is then sent through the network protocol to the web browser. The web browser uses it's private key to decrypt and extract the random private key of the web server then used the private key to decrypt the encrypted data.

Conclusion

Cryptography plays an important role in many electronic and communication system. It is also the backbone of blockchain technology. Knowing about cryptography will be helpful in building safe and secure applications.

Let's connect on Twitter @drayfocus, and Linkedin Akinola Ayomide.

Cheers!