Invasive Technologies 2023
This article is about Invasive Technologies.
Introduction with Invasive Technologies:
In this lab, we will perform an attack on the Caesar cipher in plaintext. Cryptanalysis is a technique in which the goal is to decipher a cipher without a key and obtain the plaintext. In order to perform a chosen plaintext attack on the Caesar cipher, we need to know about the Caesar cipher and the chosen plaintext attack.
STEP 1: Understanding the Caesar Cipher
The Caesar cipher is one of the oldest substitution ciphers used in the Middle Ages. Here, the plaintext is shifted down a line of the alphabet by the offset provided by the key chosen for encryption. Since the alphabet contains 26 letters, a key value of 26, when used to encrypt a message, returns the same plaintext as the ciphertext. With key 2, A in plain text becomes C, C becomes E, and so on. For example – if we choose INFOSECINSTITUTE as plaintext and key 5. We get the ciphertext by shifting I by 5 to N, N by 5 to S and so on. The plaintext and ciphertext are shown below:
Plain text: INFOSECINSTITUTE
Cipher text: NSKTXJHNSXYNYZYJ
It should be noted that the shift in each case exceeds the range of the alphabet it should be rolled over. For example, the plaintext ZOO, when encrypted with key 2, becomes BQQ in the ciphertext. Here Z is shifted by two to get B.
Step 2: Overview of the selected plaintext attack
Now that we have an idea of the Caesar Cipher, we get a comprehensive overview of selected plaintext attacks. In a chosen plaintext attack, the cryptanalyst has access to the cipher block/system. Here, the cryptanalyst chooses any plaintext and obtains ciphertext for it using an encryption algorithm. Once the ciphertext is obtained, the cryptanalyst uses the plaintext, ciphertext pair to analyze and derive information about the key. This differs from the known plaintext attack, where the cryptanalyst already knows at least one set of plaintext, ciphertext.
Related article:Everything you need to know about Ethical Hacking as a Career by Blackhat Pakistan 2023
Step 3: Executing a chosen plaintext attack on the Caesar Cipher
Now we take some plain text and encrypt it using a random number that has a value less than 26 as the key. This masks the key.
Plain text 1: CRYPTOGRAPHY
Now we assign a random number to the key variable. To do this, open Python from a terminal in Kali Linux.
After opening python, let’s import random to generate a random integer. And assign a variable called key a random value between 1 and 25. Let’s also list a list called plain_text. This is shown on the following page:
Now we encrypt the message using a random key. Let’s declare an empty list called cipher_text. For this we need Python’s chr() and ord() functions. chr() takes an integer as a parameter and converts it to a character with an equivalent ASCII value. ord() does the opposite.
Now let’s print cipher_text to see what the ciphertext is. This is shown below:
We now have a pair of ciphertext in plaintext.
Plain text: CRYPTOGRAPHY
Cipher text: QFMDHCUFODVM
It should also be noted that since then the ciphertext is generated using a random function. It may vary for different execution times and different execution machines.
Now that we have both the plaintext and ciphertext fields, we simply parse the relationship between them to find the key. Here we can see that the alphabet “C” in plaintext is shifted by 14 to become “Q”; The “R” also shifts and flips to become an “F” and so on…
C (+ 14) [D-1, E-2, F-3, G-4, H-5, I-6, J-7, K-8, L-9, M-10, N-11, O-12, P-13, Q-14] = Q
R (+14) [S-1, T-2, U-3, V-4, W-5, X-6, Y-7, Z-8, A-9, B-10, C-11, D-12, E-13, F-14] = F
This gives a key of length 14. (May vary in your case)
Now let’s print the variable key to see what was successful.