Introduction to computer networks

Good day, everyone! This is my first post on the CyberFish blog and the beginning of a series of articles that could be later converted into a complete course about computer networks and cybersecurity.

I hope I will provide information that is easily digested and challenging to find. I always say that to know how something works, you need to know the basics, so we will start from the complete basics and gradually increase complexity.

Think deep, learn simple, complex things are always a set of simple ones.

How network cards actually work

First, let’s talk about how computers store and process information. As you probably know, computers use the binary system, which is based on the use of 0s and 1s to represent data. These 0s and 1s are actually the states of electric current, and they are called ‎‎‎‎‎‎bits. So, either there is a current or no current. For example, to display an image on your monitor, we need to have a set of 0s and 1s stored somewhere we can read them. Moreover, we need to know the exact size of the image so we know when to stop reading the information, the location of the first bit from where we need to read the image, and some extra information about the image type so we can display this set of bits using the appropriate algorithm (PNG/JPG/SVG, etc.).

The same idea of reading the set of bits is used in transferring data between computers, and it is also very similar to reading an image. The only difference is that we do not have an exact physical location where the data is stored, we need to send this data and receive it. To send the image over to another computer, we could try to convert bits to different voltages for example, 1 could be +10v, and 0 could be -10v, but the problem is that we do not know how to properly read that information. If we would be sending a series of multiple 0 bits, how do we make sure we read the number of 0 correctly? We should have some timeframe for each of these electrical impulses, and sure there is one called clocking.

The idea for clocking is simply to sync the frequencies of writing information and reading the information between sender and receiver.

Every N milliseconds we should be reading electrical impulses from the wire and checking voltages. For example, look at how we have read those three 1's in the picture above, we were just checking the impulses with the same frequency, and all three times we checked the voltage, it was +10v, so we converted that set of bits to 1 1 1

Basically, the sender should make sure that the receiver is on the same page with him and can accurately understand him. Before even sending the data, both parties choose the best way to synchronize. It could be that the sender provides the clocking information, or they both get that information from some other common device source. Either way, when they are both on the same page, the actual sending of information starts.

We also need to know when to start and stop reading the information. For that purpose, we could use the start bit voltage as +10v and the stop bit as the absence of transition. Think of this case – if we do not have the start bit, how would we determine the beginning of the data frame if it starts with a 0 bit? The absence of information also tells us that the data frame is already complete. The picture below represents the starting and end bits.

Here, we have sent the 8 bits of information, 8 bits are called a byte.

So far so good, we can send bits of information and a receiver can properly read it, everything sounds great. But now we have other problems. How to make sure someone received our data? How do they know we are actually sending a picture and not a video or text. What if the data we are sending is corrupted?

Data integrity, and security

If we are dealing with electrical impulses, we should account for multiple factors that could degrade or even completely mess up our data. Interference from other electrical wires or sources could lead to invalid voltages. Long distances reduce the power of signals.

For the problem of reducing the signal power, we could enhance the signal with the proper voltages once we see any degradation. This technique is used, but it does not guarantee we will receive the exact data. We need to make sure the data we are sending is valid, if not we should be just skipping it.

Let’s see what happens if we try to treat our data as data, plus CRC :

The idea of CRC (cyclic redundancy check) is to provide a unique chunk of information with which we could later detect whether the data was correct. A very simple implementation of CRC is to just grab the bytes of data and hash them. Hashing – a process of applying a function on a set of data that results in a unique and fixed-size data set. On the receiving end, we can just do the same with the data – hash it, compare CRC with our hash, and if they are not equal – treat data as not correct. This method is used to transmit data over a wire and in wireless connections such as Bluetooth and Wifi.

As you already figured out, to send any data to other computers, the data needs to travel pretty long distances over the wire. There will always be other devices along the way, that retranslate your data to other devices, that send data forward, and so on until the data is received. We will talk about this process later, but right now I would like to ask this question – is it possible to capture your data along the way and see what are you sending?

The short answer to this question is “Yes it is”. In theory, it is even possible to crack open the wire, connect to it, and sniff all the electrical impulses. In public places such as coffee shops or an airport, when you connect to the wifi network, you also should be cautious. There are multiple ways to sniff all your data because attackers could fake the websites you are using to look like a legit website, but under the hood just store a username and password from your account and redirect to a legit website so you even do not know that something is wrong. 

So how we even protect against such cases? For now, we have a data encryption mechanism that is called TLS/SSL. In short, one of the implementations is to have 2 pairs of keys for both receiver and sender, so-called private and public keys. The public key is transmitted to the device with which you are communicating and is used to encrypt data that will be sent to your device. The private key should be stored on your device only and is used to decrypt the data. This is a very short explanation; we will have a more detailed one in future articles.

Internet Protocols

Moving forward, another major ability we would like to have is to actually know the type of data we are sending. Remember the example with an image? We knew that it was an image, so we would use the proper program to open it. The same principle applies to networks, sometimes we would like to send just plain text data, sometimes an image or a video stream. We also would like to know if our data was received, or in some cases, we should not care about it. Moreover, we would like to send and identify messages, which help us maintain healthy network connections.

For example, instruction messages that are similar to the questions like “Was the data received” and answers “Yes” or “No”. The sequence of messages and messages data structure is called a protocol. In the next article, we will discuss our first internet protocol, but for now, please ask any questions in the comments section. I sincerely hope that right now you have even more questions than before and welcome to the exciting world of computer networks!