# Cryptography

In this tutorial, you will learn the basic concepts of cryptography. After reading this tutorial, you will learn about encryption, decryption, cryptography categories and principles, key types, and ciphers.

Contents:

## Cryptography Introduction

Basically, cryptography means secret writing. Cryptography is a method that converts the original human-readable plain text message into ciphertext. In short, encryption and decryption of data are done.

• Cryptography prevents data from reaching an intruder, since the data is encrypted, the intruder will not be able to decipher the data because he does not have the key.
• Cryptography is a combination of cryptanalysis and cryptology.
• Cryptanalysis: Cryptanalysis knows how to break the cipher. When two users are communicating and an authorized person is listening to their data, it is known as cryptanalysis.
• Cryptology: To achieve unauthenticated communication between two users to listen to traffic.

## Encryption and Decryption

Encryption and decryption are operations performed on data. Encryption means converting human-readable data into ciphertext. Decryption means decrypting the ciphertext into the original message.

• When we want to perform encryption on data three things are required: plain text, encryption algorithm, and encryption key. In consequence, the encryption of the data creates ciphertext.
• C.T. = EK(P.T.)
• P.T. = Plain Text
• C.T. = Cipher Text
• EK = Encryption algorithm with encryption key
• Similarly, to decrypt the ciphertext we need the ciphertext, decryption algorithm, and decryption key. As a result, we get our original message.
• P.T. = DK(C.T.)
• DK = Decryption algorithm with decryption key
• Basically, in cryptography, ciphers are known as encryption and decryption algorithms.

The data generated by the sender is encrypted using an encryption algorithm and key. When the receiver receives the data, it uses the key to decrypt the data.

## Categories of Cryptography

Symmetric key (secret key) and asymmetric key (private key and public key) cryptography algorithms are categories of cryptography algorithms
Symmetric Key Cryptography: In this algorithm, the key is shared between the sender and the receiver.

The diagram below explains the symmetric key cryptography algorithm.

• As shown in the figure, both the sender and the receiver have the same key, which is the shared key. The sender encrypts the data using the key and encryption algorithm.
• Upon receiving encrypted data, the receiver decrypts the data using the same key used by the sender and the decryption algorithm.

Asymmetric-key Cryptography: In this algorithm, two keys are used, public key and private key. The public key is known to all, whereas private key is available to an individual only.

The diagram below explains asymmetric-key cryptography.

• As shown in the figure, PC-1 encrypts the data using the public key of PC-2, as the public key is publicly available.
• Once, PC-2 has received the encrypted data, it decrypts the ciphertext using its private key and generates an original message.

## Types of Keys

When we use categories of cryptography, three keys are used, secret key, the public key, and private key.

The diagram below shows the keys used in cryptography.

• As shown in the figure, the secret key is used when the symmetric-key algorithm is used. In a symmetric-key algorithm, the key is shared between the sender and receiver and both use the same key for encryption and decryption.
• In the asymmetric-key algorithm, public and private keys are used for encryption and decryption.

## Substitution Ciphers

Substitution ciphers are encryption methods, used to encrypt data. In this method, each letter or group of letters in the plain text is replaced by another letter or group of letters. The Caesar cipher is one of the oldest replacement ciphers.

Caesar Cipher: In this cipher, the letters of the plain text are replaced with other letters. For example, a replaced by E, b replaced by F, c replaced by G, and so on.

• Whenever we encrypt plain text using Caesar cipher, the key is given to us. Based on the key, the Caesar cipher encrypts the data.

The diagram below explains the Caesar cipher.

As shown in the figure, the key is given as k=3 and the plain text is abc. Now, after applying the Caesar cipher to the plain text, the generated ciphertext becomes def.

• The disadvantage of a Caesar cipher is that it can be easily broken if it contains a small amount of ciphertext. Because an attacker tries to find repeated letters in the ciphertext.
• For example, the most common letter in English is e, and also, a, i, n, o, and t are the most common letters. The most common two-letter combinations are th, in, an, and the most common three-letter combinations are the, ing, and, and ion.

## Transposition Ciphers

In a transposition cipher, the plaintext is rearranged and forms the ciphertext. Here, we have not replaced the plaintext letters with other letters, we are only replacing them key-wise.

In a transposition cipher, the plaintext is rearranged and forms the ciphertext. Here, we have not replaced the plaintext letters with other letters, we are only replacing them key-wise.

The diagram below explains the transposition cipher.

• As shown in the figure, given the key, `k = Krishna`. Here, the purpose of the key is to sort the columns in an alphabetic manner.
• The column with the value 1 is assumed to be the beginning of the ciphertext. This continues and the ciphertext is generated.
• If cryptanalysis wants to break the transposition cipher, it must have an idea that the ciphertext is generated using the transposition cipher.
• The cryptanalysis analyzes the pattern and looks at the frequency of e, t, a, o, i, and n to determine whether this ciphertext is encrypted with a transposition cipher.
• After finding the frequency of letters, cryptanalysis has to estimate the number of columns.
• Once, the number of columns is found, cryptanalysis has to order the columns.
• After performing and analyzing all the steps, there may be a possibility that cryptanalysis has found the original plaintext.

We can make our ciphertext unbreakable by using one-time padding. For that, we have to choose a key that contains a random bit string. The plaintext is converted to a bitstream, and the XOR operation is performed between the plaintext bit string and the key bit string, bit-by-bit. As a result, we get a ciphertext that cannot be broken.

• The disadvantage of this method is that the sender and receiver must carry a written copy of the key. Also, the total amount of data that can be transmitted is limited by the amount of key available.
• If the sender and receiver lose their synchronization, the data will be lost.

## Two Fundamental Cryptographic Principles

Redundancy and freshness are two fundamental principles of cryptography. Let us understand this two one-by-one.

Redundancy: Whenever encryption is performed, all messages must contain redundant bits, so that attackers cannot send random junk, and each message can be interpreted as a valid message.

• For example, if the encryption bytes are 8 bytes, the first 5 must be zeros. This way, we can avoid the attack in which the attacker was generating a large stream of legitimate messages.
• This is the first principle of cryptography: messages must contain some redundant bits or redundancy.
• With the help of the first principle, we can prevent an attacker from sending garbage.

Freshness: Requires some method to check and validate that each received message is fresh, that is, the most recently sent message.

• Using this rule prevents an attacker from playing back with valid old messages.
• For example, a timestamp is added to each message, let’s say the timestamp is 20 seconds. So when the receiver receives the message, it compares the newly arrived message with the previous one, so that it can remove the duplicates.

## Key Points to Remember

Here is the list of key points we need to remember about “Cryptography”.

• Cryptography prevents data from reaching an intruder, since the data is encrypted, the intruder will not be able to decipher the data because he does not have the key.
• Encryption means converting human-readable data into ciphertext. Decryption means decrypting the ciphertext into the original message.
• Symmetric key (secret key) and asymmetric key (private key and public key) cryptography algorithms are categories of cryptography algorithms.
• Substitution ciphers are encryption methods, used to encrypt data. In this method, each letter or group of letters in the plain text is replaced by another letter or group of letters.
• In a transposition cipher, the plaintext is rearranged and forms the ciphertext. Here, we have not replaced the plaintext letters with other letters, we are only replacing them key-wise.
• In One Time Padding, the plaintext is converted to a bitstream, and the XOR operation is performed between the plaintext bit string and the key bit string, bit-by-bit. As a result, we get a ciphertext that cannot be broken.

If you find any mistake above, kindly email to [email protected]