Saturday, December 15, 2018

Symmetric and Asymmetric Cryptography

Having learned about cryptography in the previous article, it is now time to learn about the types of cryptography. You are right, nothing is complete till we understand its types and subtypes and so on. Remember, your best friends, Alice and Bob!!! They are going to help us understand the types of cryptography.

Before we go into the details, we ought to recapitulate a few terms. 

1. Plain text – Data in a readable or understandable format.
2. Ciphertext – Random and unreadable text 
3. Encryption – Process of converting plain text into cipher text.
4. Key – Sequence of random bits
5. Algorithm – Rules by which encryption and decryption will take place.

It is really important to clearly understand these terms, else, the journey ahead will be difficult. So lets us begin.

Cryptography algorithms are either symmetric algorithms, which use symmetric keys (also called secret keys), or asymmetric algorithms, which use asymmetric keys (also called public and private keys). I know, this can be confusing, if you read this the first time, however, you’ll be able to sail through if you pay close attention.

If you and I share the same password, we are using the symmetric algorithm and if we use a public and a private password, we are using the asymmetric algorithm. This is not technically correct, however, explains it in a manner that you can understand.

Symmetric Algorithm

Alice and Bob, as usual, want to communicate with each other. Alice has an old age secret recipe of pancakes which Bob has requested from Alice. Given the current scenario of data breaches happening everywhere, Alice is skeptical of sending it as such. She discusses with Bob and they both decide to use symmetric cryptography for this purpose. In a cryptosystem that uses symmetric cryptography, the sender and receiver use two instances of the same key for encryption and decryption. This means that if Alice uses the key “123@encrypt” for encrypting, Bob will also use the same key to decrypt it. Each pair of users who want to exchange data using symmetric key encryption must have two instances of the same key.

The diagram below also illustrates the same.

Clearly, in symmetric encryption, it is the secrecy of the key that plays the most important role. If 3 people wish to communicate with each other, all 3 must have the same key and most importantly, all 3 of them must keep it secret. Hence, keeping the key secret is a big task, if there are many people involved.

We had learned that cryptography helps us achieve confidentiality. Symmetric cryptography can help us achieve that, but, can it help us achieve integrity, non-repudiation or authentication? Think for a minute. What is integrity? No unauthorized modification. But if the secret key is no longer secret, you cannot be 100% sure that no modification has taken place. There is also no way to prove who sent the message if two or three people are using the same secret key.

Monday, December 3, 2018

Understanding Cryptography

“ $%^*^* Nh%&gfg  K97@#”. Well, I’m 100% sure that you did not understand what I meant to say through these words. This is what cryptography is all about. Nah, don’t think that if you are unable to read what was written, it becomes an implementation of cryptography. When you convert plain text (readable text) into something that cannot be read (deciphered) often called ciphertext, it is known as cryptography.

Why would you want to convert something which is readable into gibberish? From time immemorial, human beings have kept secrets to protect themselves and their countries. For this very reason, information must be protected and this assurance can be further provided by encrypting the data, ie. the process of converting plain text into cipher text. Remember, the three pillars of information security – CIA. Cryptography helps implement the confidentiality principle.

The formal definition is as follows:

Cryptography is a method of storing and transmitting data in a form that only those it is intended for can read and process. It is considered a science of protecting information by encoding it into an unreadable format.

Now it’s time to learn new terms :

Encryption is a method of transforming readable data, called plaintext, into a form that appears to be random and unreadable, which is called ciphertext. Plaintext is in a form that can be understood either by a person (a document) or by a computer (executable code).

Once it is transformed into ciphertext, neither human nor machine can properly process it until it is decrypted. This enables the transmission of confidential information over insecure channels without unauthorized disclosure.

The algorithm is the set of rules also known as the cipher, dictates how enciphering (encryption) and deciphering (decryption) takes place. The secret ingredient that makes this algorithm so hard to break is the KEY.

If you are confused, don’t be. We need to understand all of this through an example.

In cryptography, you need to make friends with Alice & Bob. They are the 2 most famous people in the world of cryptography. Now Alice wants to send a message to Bob. The message is “I passed my CISSP exam and Mayur helped me a lot in it”. This is what is plain text as you were able to read it. Bob, however, doesn’t want the world to know this. So Bob converts this message to “@#$% B$CG &*()&%VBNJIJJM” which is unreadable. He converts it to a ciphertext which you and I can’t read. How does he do that? He uses an algorithm and encrypts it. In order to do so, he uses a KEY, similar to a password or passcode which can change it back. It’s like using a lock and only the correct KEY combination can open the lock.

In encryption, the key (crypto variable) is a value that comprises a large sequence of random bits. Is it just any random number of bits crammed together? Not really. An algorithm contains a keyspace, which is a range of values that can be used to construct a key. When the algorithm needs to generate a new key, it uses random values from this keyspace. The larger the keyspace, the more available values can be used to represent different keys—and the more random the keys are, the harder it is for intruders to figure them out. For example, if an algorithm allows a key length of 2 bits, the keyspace for that algorithm would be 4, which indicates the total number of different keys that would be possible.

All this makes up a cryptosystem which contains all the hardware and software that is required to implement this.

In a nutshell, cryptography helps you protect your information by utilizing rules which are driven by a key.

What are your thoughts on this?

Monday, November 19, 2018

Understanding NAT – Network Address Translation

If you would like to send a letter to me, what would be the most important aspect for you to send it across? My address. If you would have observed, we usually write the address in a certain format – building number, followed by area, city, state and then the pin code. Why do we do that? To avoid confusion. In a similar fashion, computers when they need to talk to each other, need to use the addresses. The Internet uses the IP addressing scheme, through which each computer on the Internet is assigned an IP address and that can be used for communication. Now think, how would you communicate if these addresses go missing? Read on to find out.

A long time ago, when the Internet came into existence, the concept of IP addresses came to life. This was called the IPv4 addressing scheme. This scheme involved the addresses being recorded as say, for example, So every computer on the Internet got one such address. Over time, with the population explosion, the number of computers and devices connected to the Internet increased so much that the number of addresses went in short supply. To overcome this problem, IPV6 was introduced which could solve the problem as the number of addresses offered by this scheme was extremely large (2^128). However, this scheme also required changes to be done with the software and the hardware which we used. Intelligent minds came together to find a short-term fix until we could start using the IPV6. This solution was called NAT – Network Address Translation.

To understand NAT, let’s take an example. Imagine that you and I live in a society where there are a lot of apartments. Let’s call this place as “Security Society”. My flat number is 3331 and yours is 3335. In a similar fashion, there are hundreds of apartments in this society. When you send a letter outside, you write your complete address – Flat Number 3331, Block S, Security Society. However, the main security guard at your society’s entrance puts your letter in another envelope and changes the address to “Security Society” and hands it over to the postman for delivery. When the postmaster brings back the reply, the delivery address is just mentioned as Security Society and not the complete address. Hence, he hands it over to the security guard at the entrance and goes back. The guard understands that this letter belongs to you and hands it over to the correct address - Flat Number 3331, Block S, Security Society. 

Let’s apply the same analogy to the world of computers to understand NAT. When a message comes from an internal computer with the address of, for example, the message is stopped at the device running NAT software (security guard), which happens to have the IP address of (address changed). NAT changes the header of the packet from the internal address,, to the IP address of the NAT device, When a computer on the Internet replies to this message, it replies to the address (Security Society). The NAT device (security guard) changes the header on this reply message to (actual address – flat number) and puts it on the wire for the internal user to receive. Thus, NAT hides internal addresses by centralizing them on one device, and any frames that leave that network have only the source address of that device, not of the actual internal computer that sends the message.

NAT provides great security benefits in addition to solving the problem of the number of IPV4 address. When an attacker wants to target a system, he will not have the actual IP address and thus will continue to attack the natted IP address. Take a cue from the analogy shared above, the spam or marketing emails from companies will land up with the security guard who will just discard them and you will not be bothered.

There are 3 types of NAT implementation:

1. Static Mapping – Here the NAT software will have a bunch of public IP addresses and every private address will be mapped to a particular system always. So computer A always receives the public address x, computer B always receives the public address y, and so on. This is generally used for servers that need to keep the same public address at all times.

2. Dynamic Mapping – The NAT software will again have a bunch of public IP address, but this will get allocated dynamically to the private addresses. So if you send a request to communicate you will be given the public IP A which is first in the list, unlike static mapping where you were always mapped to public IP C.

3. Port Address Translation (PAT) – A pat on the back for you since you have made it to this point in the article. PAT is an extension of NAT and helps us to reduce the cost of buying multiple IP addresses. Here we will have only one IP address similar to one security guard at the main gate. Let’s take an example - The NAT device has an IP address of When computer A needs to communicate with a system on the Internet, the NAT device documents this computer’s private address and source port number (; port 43,887). The NAT device changes the IP address in the computer’s packet header to, with the source port 40,000. When computer B also needs to communicate with a system on the Internet, the NAT device documents the private address and source port number (; port 23,398) and changes the header information to with source port 40,001. So when a system responds to computer A, the packet first goes to the NAT device, which looks up the port number 40,000 and sees that it maps to computer A’s real information. So the NAT device changes the header information to address and port 43,887 and sends it to computer A for processing. 

Although NAT is a short-term solution, it has been well received by the networking and the security community. Eventually, the world will move to IPV6 in entirety, but NAT and PAT offer cost-efficient and secure ways to handle the problem of depleting IP address today and even in future.

What are your thoughts on this? 

Saturday, October 27, 2018

Asynchronous & Synchronous Communication

Try to read the sentence written after this statement - “youwillpasscisspexamifyoustudyhard”. Clearly, you need to focus on the letters and your mind will try to discern the different words for you. Similarly, if I speak to you without pausing, it would again be difficult for you to discern and understand what I am communicating. So irrespective of the way we communicate – verbal or written, we need to follow certain grammatical rules so that the other party is able to clearly discern and understand what is being said. These grammatical rules for the written language include punctuation symbols such as comma, semicolon, spaces etc. while for verbal communication we use various aspects such as pausing, hand gestures, tones. 

In a similar manner, technological communication protocols also have their own grammar and synchronization rules when it comes to the transmission of data. We have two kinds of transmission ways – Synchronous & Asynchronous. Both of them utilize aspects similar to verbal and written communication. 

Asynchronous transmission utilizes bits for starting and pausing the transmission. If two systems are communicating over a network protocol that employs asynchronous timing, then “start” and “stop” bits are used. The sending system sends a “start” bit, then sends its character, and then sends a “stop” bit. This happens for the whole message. The receiving system knows when a character is starting and stopping; thus, it knows how to interpret each character of the message. It is similar to how we communicate in a written letter – I will insert spaces, commas, full stop, etc. to indicate “start”, “pause” or the “end” of the letter.

Just like when we speak verbally, we do not explicitly say “Pause” or “Stop” or “Start” to indicate the beginning or an end of a conversation, in a similar manner, synchronous transmission does not employ any explicit “start” or “stop” bits to indicate the beginning or the end of any transmission. If two systems are going to communicate using the synchronous transmission technology, they do not use start and stop bits, but the synchronization of the transfer of data takes place through a timing sequence, which is initiated by a clock pulse. So, synchronous communication protocols transfer data as a stream of bits instead of framing them in start and stop bits. The synchronization can happen between two systems using a clocking mechanism, or a signal can be encoded into the data stream to let the receiver synchronize with the sender of the message. This synchronization needs to take place before the first message is sent.

In simple terms, asynchronous transmission is like a communication that happens on the satellite phone where the sender and receiver both say “Over” to indicate that they have sent the message while the synchronous transmission is like a normal communication that is done where our pauses at specific intervals indicate the start and the end of transmission. 

Now, having understood this, a question would pop up in your mind. What is the use of this transmission techniques? In today’s digital age where everything is just data that needs to be sent across, there must be rules that govern this transmission. In addition to the rules, the two systems must agree on a way to receive and process data. Synchronous transmission is utilized where we have a predictable data stream (such as Netflix streaming) while Asynchronous transmission is utilized where an unpredictable amount of data can be sent across (Internet connections, torrent downloads).
Ultimately, it’s all about timing.

And speaking of timing, this is a special article for me, as this is the 75th one. :)

Monday, October 22, 2018

The TCP Handshake

We learned about the TCP protocol in the article “Understanding TCP and UDP.” A brief mention was made in that article on the 3-way handshake process. Before we delve into that further, we must recapitulate about the TCP (Transmission Control Protocol).  TCP is a reliable and connection-oriented protocol, which means it ensures packets are delivered to the destination computer. If a packet is lost during transmission, TCP has the ability to identify this issue and resend the lost or corrupted packet. 

Now, before any data is sent across, handshaking takes place between the two systems that want to communicate. Once the handshaking completes successfully, a virtual connection is set up between the two systems. It’s just like a high profile deal that gets signed. Just like in a deal, both the parties discuss on various parameters such as the financial settlement, payment of outstanding dues, shareholding etc., in a similar manner, the two hosts (systems or computers) must agree on certain parameters, data flow, windowing, error detection, etc. 

The following diagram will help us understand the agreement that takes place between the two hosts.

The host (lovely lady here) that initiates communication sends a synchronous (SYN) packet to the receiver. This means that “Would you be interested in establishing a data connection with me?”
The receiver acknowledges this request by sending a SYN/ACK packet which translates to “Yes, I am interested in taking this conversation further. I have acknowledged your request and sending you the details of how to communicate with me.”

The lady accepts this “SYN+ACK” packet and sends an “ACK” packet which translates to “Ok… I understand the terms and conditions. Let’s begin the conversation.”

After this, the host and the other system starts transmission of data between each other. If all were so good in this world, we would not have to deal with the following problems which arise when the lovely lady turns out not to be so lovely.

The lady here has a change of heart and decides to play a trick on the receiver. What she does is, she withholds the last step of the handshake – “ACK”. Since the 3 way-handshake is not complete, the other system keeps on waiting for that. In the meantime, this lady starts another connection with the server and again withholds the last “ACK” packet. If she does it multiple times, it results in what is called as a “SYN Flood” attack. This is actually flooding the victim system with SYN packets, eventually, the victim system allocates all of its available TCP connection resources and can no longer process new requests.

This is an example of DoS attack – Denial of Service. The victim system will not be able to provide any services to any client as all its resources are locked with one system. 

There is another attack – DDoS attack. This is a distributed denial of service attack. Here the attack is from multiple different systems which leave the handshake open and the result is again the denial of service. To put it in the same example, let’s consider that this lovely lady brings together a lot of her friends and ask them to start the handshake process with the victim and leave it in the middle. This would result in a DDoS attack.

There is one more attack mechanism we need to learn about before we say goodbye to each other.

One of the values that are agreed upon during a TCP handshake between two systems is the sequence numbers that will be inserted into the packet headers. Once the sequence number is agreed upon, if a receiving system receives a packet from the sending system that does not have this predetermined value, it will disregard the packet. This means that an attacker cannot just spoof the address of a sending system to fool a receiving system; the attacker has to spoof the sender’s address and use the correct sequence number values.

If an attacker can correctly predict the TCP sequence numbers that two systems will use, then she can create packets containing those numbers and fool the receiving system into thinking that the packets are coming from the authorized sending system. She can then take over the TCP connection between the two systems, which is referred to as “TCP session hijacking”.