black audio mixer
Mon Oct 31

The Basics of Cryptography

Imagine you send a message to your business partner informing him or her that you need the debt payment immediately while providing the destination to which the payment should be transferred which is “A”. After reading the email, your colleague sends the money right away and notifies you that a certain amount has been transferred. After some time, you still don’t receive any notification from your banking apps telling you that the money has been received. Despite your accusations, your business partner insists that he or she has fulfilled its obligations. Further investigation leads you to discover that the destination had been changed to “B” rather than “A.” What a disaster this will be for your entire company and business relationship! To avoid such occurrences, cryptography comes in.

What is cryptography?

Cryptography is a study of securing communication between the sender and receiver, so that only the intended recipient could read the information. To achieve this secure communication between both parties, we use an algorithm to convert original to modified one called cipher text. This process of converting the original text to cipher text is called encryption and the process of reverting it back is called decryption.

Types of cryptography

In general, there are 2 types of cryptography, symmetric key cryptography and asymmetric key cryptography. What differentiates between the two is the key used for encryption and decryption.

Symmetric key cryptography

Symmetric key cryptography uses the same key for both encrypting and decrypting.

Classical cryptography

There are two types of classical cryptography, substitution and transposition cipher. For greater complexity, both are usually applied in tandem.

Substitution cipher

One of the most widely known encryption techniques is the Caesar cipher. Got its name from famous Roman General Julius Cesar, he uses a technique categorized as substitution cipher. The concept is quite simple. You just substitute each of the letters to another one based on the fixed number sorted from the whole 26 latin letters.

ABCDEFGHIJKLM
NOPQRSTUVWXYZ

As you can see, all latin letters were divided into two groups with a total of 13 letters each. To encrypt your message, you can just simply replace each one to its partner (see table above). For example, “HELLO” message will be encrypted to “URYYB”. To decrypt the cipher,you can simply do the same thing for each letter. This method is called ROT13 (Rotate by 13 places) and known to be the earliest .

Transposition cipher

With substitution cipher, the plain text changes (substituted), while with the transposition cipher, it is reordered without changing its letter. It then follows one of 5! permutation as it consists of 5 letters. In order to decrypt the cipher, the recipient has to know the code permutation being used so the permutation can be inverse. Thus, the original plain text could be obtained. Taking the same word “HELLO”, it can be transposed into something like “LOHEL”.

We think it would be easier to explain it using a more word. You have “PIE” (123) as plain text. Because of the words consists of 3 letters, you may have several ways to encrypt your plain text like “PIE” (123), “PEI” (132), “IPE” (213), “IEP” (231), “EPI” (312), “EIP” (312). Because none of the letters are repeating, you can conclude that it follows 3! permutation which is 6 possible rearrangement. Just for your information, the number inside the bracket only represents the order of each letter and not the actual plain text. In order to decrypt the cipher, you have to know which pattern the sender uses (key). Assume that the sender uses the 213 pattern and you get IPE as cipher. As you know the pattern, you can reorder the words back into the correct order 123 which is “PIE”.

Modern cryptography

Nowadays, more types are introduced. In modern cryptography, the techniques rely heavily on binary as the computer uses it to communicate. Because of that, the characters need to be converted into binary digits (bits). In example, we will use the same word “HELLO”. Take a look at the table below.

Plain Text


H| E| L| L| O
ASCII Value
72| 69| 76| 76| 79
Binary
1001000| 1000101| 1001100| 1001100| 1001111

The word HELLO can be converted into ASCII values which are H (72), E (69), L (76), L (76), O (79). As you have the decimal value now, you may convert it to binary which is 1001000 1000101 1001100 1001100 1001111. To simplify things, we will only use a single letter “H”. As you can see, H is translated into 1001000 in binary (7 bits).

Stream cipher

In a stream cipher, bits are individually encrypted into cipher text. Most stream cipher works by following XOR logical gate. You can see the XOR truth table below for reference. 0 represents as false and 1 represents true.

| Input | Output | | ----- | ------ | ------- | | A | B | A XOR B | | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 0 |

XOR Truth Table

You may have been familiar with AND and OR logical operations before. XOR works just like OR, but differs only on the last condition. In OR logical operation, true OR true equals true while on the XOR logic, true XOR true equals false.

Back to the example, we can take our input , the “H” character as A and we take our key as B. At this point, we may use any key. For the sake of of this example, let’s just use 0101101 as a key.

| Input | Output | | ---------- | ---------- | ------------ | --- | ------------- | ----- | ----------- | | A | B | A XOR B | | Plain text | ASCII | Binary input | Key | Cipher binary | ASCII | Cipher text | | H | 72 | 1 | 0 | 1 | 101 | e | | 0 | 1 | 1 | | 0 | 0 | 0 | | 1 | 1 | 0 | | 0 | 1 | 1 | | 0 | 0 | 0 | | 0 | 1 | 1 |

By applying XOR logic, we get new binary digits that we can refer to the new character “e”. If the recipients have the same key, they could get the original plain text back. How? You can switch the position and use cipher binary as input.

You might be wondering now, how could “H” character with ASCII value 72 equals 1001000 in binary? Binary is base-2. Therefore, it uses powers of 2. So, what is base-2 exactly? Let’s take a look at our numbering system. I have a number 9234. In our numbering system, we use base-10 instead of base-2. You can say that 9234 is basically 9103 + 2102 + 3101 + 4100 = 9234. In the base-10 system, we can use the digits ranging from 0 to 9 which totals 10 different digits. Unlike our numbering system, in base-2 (binary), there are only two digits possibilities, which are 0 and 1. Therefore, we can convert 1001000 into 126 + 025 + 024 + 123 + 022 +021 +0*20 = 72.

Block cipher

While stream cipher encrypts the information bits-by-bits, block cipher encrypts the information in chunks or blocks. Instead of taking the bits individually, it will split the information into fixed size.

If we decide to convert our input using a block cipher, we have to split the binary into several chunks, let’s say 2 bits at a time (in the real case however, the block is way bigger than 2). Using the same letter, we have our binary digits 1001000 (7 bits ASCII). In today’s world, ASCII is usually stored in 8 bits while 0 bit is used for the last bit.

By knowing this, we can take our example letter “H” as 01001000. Using block cipher of 2 we now get 01 00 10 00. Binary only allows 0 and 1, so we use a transposition cipher. Using the same principle, we could modify the pattern as long as both parties have the keys.

Asymmetric key cryptography

Asymmetric key cryptography doesn’t use the same key for both parties for communication for encryption and decryption. Instead, both parties have their own keys, public key and private key. Public key and private key are mathematically related. As the name suggests, the public key belongs to the public domain. The private key only belongs to the party where the key is generated.

Let’s say, Tom needs to send a message to Bob. In order to be able to communicate securely, Bob will give Tom his public key. And then, Tom sends the message and encrypts it using the public key that has been given from Bob. Bob will receive the encrypted message (cipher text) and needs to decrypt it first. This is when Bob’s private key will be used to decrypt the message.

It is important to know that to establish the communication, the receiver needs to send his or her public key to the sender. Belongs to the public domain, it means that the public key is accessible to anyone. In this case, not even Tom is able to decrypt the message he writes. You can think of it as pairs. Thus, only the right private key pair is usable.

Conclusion

Cryptography is a vital tool for ensuring the security and integrity of communication in the digital age. It allows us to protect our data, transactions, and identities from unauthorized access and manipulation. In this article, we have explored two main types of cryptography: symmetric key and asymmetric key. We have also discussed some examples of classical and modern techniques for encrypting and decrypting information using different keys and algorithms. Whether we are aware of it or not, cryptography plays a crucial role in our everyday lives, from online banking and shopping to social media and messaging. By understanding the basics of cryptography, we can appreciate its importance and applications in various domains and scenarios.