0% found this document useful (0 votes)
32 views6 pages

Information Security (3170720) Lab Manual

pdf

Uploaded by

Aachal Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

Information Security (3170720) Lab Manual

pdf

Uploaded by

Aachal Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

230283107001

Information Security (3170720) Lab Manual

Practical 1: Implement Caesar Cipher Encryption-Decryption and Perform Brute Force


Attack

AIM:

To implement Caesar Cipher encryption and decryption technique and perform brute force
attack to break the cipher.

Objectives:

• To understand the working of Caesar Cipher (a classical substitution cipher).


• To implement Caesar cipher encryption and decryption.
• To apply brute-force attack to decrypt ciphertext without knowing the key.
• To analyse the limitations and security strength of Caesar cipher.

Background / Preparation:

The Caesar cipher is one of the earliest and simplest ciphers known. It is a type of
substitution cipher where each letter in the plaintext is shifted a fixed number of positions in
the alphabet.

For example:
With a shift of 3, A becomes D, B becomes E, ..., Z becomes C.

Encryption:
E(x) = (x + k) mod 26

Decryption:
D(x) = (x - k + 26) mod 26

Where x is the position of the character, and k is the key.

A brute-force attack tries all possible shifts (i.e., 26 for English alphabet) to decrypt the
message.

Basic Understanding:

• Substitution cipher basics.


• ASCII and character manipulation.
• Modulo arithmetic.

1
230283107001

Information Security (3170720) Lab Manual

• Concepts of symmetric key encryption.


• Basics of brute-force attack in cryptanalysis.

Example:

Plaintext: HELLO
Key (k): 3
Encrypted Text: KHOOR

Decryption using key 3: KHOOR → HELLO


Brute-force: Try all 26 keys to recover plaintext.

Tools / Material Needed:

Hardware:

• A computer system (Windows/Linux/Mac)


• Minimum 2 GB RAM
• Keyboard and monitor

Software:

• Programming language: Python / C / Java (any one)  Text Editor or IDE: VS Code
/ Eclipse / Notepad++
• Compiler/Interpreter as per language

Procedure:

Input:

• Plaintext message (e.g., "HELLO")


• Key (shift value for encryption)
• Ciphertext (for brute-force attack)

Process:

1. Read the plaintext and key.


2. Apply Caesar Cipher encryption logic.
3. Display the encrypted message.
2
230283107001

Information Security (3170720) Lab Manual

4. Use the encrypted message as input for decryption.


5. Try each possible key (0 to 25) to decrypt and show all possibilities (Brute-force
attack).
6. Identify correct plaintext from brute-force output.
Output:

• Encrypted ciphertext from given plaintext and key.


• Decrypted plaintext using correct key.
• All possible plaintexts from brute-force attack.

Steps:

1. Start the program.


2. Ask the user for a plaintext and a key.
3. Encrypt the message using Caesar cipher logic.
4. Display the ciphertext.
5. Ask the user for ciphertext to decrypt.
6. Try all 26 shifts (0 to 25).
7. Display each decrypted output for brute-force analysis.
8. End program.

Sample Code (Java):

import java.util.Scanner;

public class CaesarCipher {

// Encryption method public static String


encrypt(String text, int key) { StringBuilder
result = new StringBuilder();
key = key % 26; // ensure within 0–25

for (char ch : text.toCharArray()) { if


(Character.isUpperCase(ch)) { char c =
(char) ((ch - 'A' + key) % 26 + 'A');
result.append(c);
} else if (Character.isLowerCase(ch)) {
char c = (char) ((ch - 'a' + key) % 26 + 'a');
result.append(c);
} else {
result.append(ch); // keep symbols/spaces unchanged
}
}
3
230283107001

Information Security (3170720) Lab Manual

return result.toString();
}

// Decryption method public static String


decrypt(String text, int key) {
return encrypt(text, 26 - (key % 26)); // reverse shift
}

// Brute force attack


public static void bruteForce(String ciphertext) { System.out.println("\nBrute-force
results:"); for (int key = 0; key < 26; key++) {
String decrypted = decrypt(ciphertext, key);
System.out.println("Key " + key + ": " + decrypted);
}
}

// Main function public static void


main(String[] args) {
Scanner sc = new Scanner(System.in);

// Input
System.out.print("Enter plaintext: ");
String plaintext = sc.nextLine();
System.out.print("Enter key (0-25): ");
int key = sc.nextInt();
sc.nextLine(); // consume newline

// Encrypt
String cipher = encrypt(plaintext, key);
System.out.println("Encrypted Text: " + cipher);

// Decrypt
String decrypted = decrypt(cipher, key);
System.out.println("Decrypted Text (using correct key): " + decrypted);

// Brute force attack


bruteForce(cipher);

sc.close();
}
}

4
230283107001

Information Security (3170720) Lab Manual

Questions:

1. What is Caesar Cipher and how does it work?


 Caesar cipher is a classical substitution cipher where each letter of the plaintext is
shifted by a fixed number (key) in the alphabet. Example: with key = 3, A → D, B
→ E, etc.

2. Why is Caesar cipher considered insecure today?


 It is insecure because it has only 26 possible keys (for English alphabet). Brute
force can easily try all keys, and frequency analysis makes it even faster to break.

3. What is a brute-force attack? How effective is it on Caesar Cipher?


 A brute-force attack is a method of trying all possible keys until the correct one is
found. On Caesar cipher, it is very effective because there are only 26 keys.

4. How many possible keys exist in Caesar cipher for English alphabets?
 There are 26 possible keys (0–25 shifts).

5. What are the differences between Caesar cipher and monoalphabetic cipher? 
Caesar cipher: Fixed shift for all letters, only 26 keys.
Monoalphabetic cipher: Any permutation of 26 letters can be a key (26!
possibilities), making it much stronger than Caesar cipher.

6. How can frequency analysis help in cracking Caesar cipher faster than brute-force?
 In English, some letters (like E, T, A, O) appear more frequently. By comparing
ciphertext frequencies with expected letter frequencies, the correct shift can be
guessed without testing all 26 keys.

7. Modify the Caesar cipher code to handle both uppercase and lowercase characters.
 The provided Java program already handles both uppercase (A–Z) and lowercase
(a– z) characters separately, while keeping non-alphabetic characters unchanged.

8. Write Caesar cipher logic in your preferred language and test with different inputs.
 Code is written above and the output is

5
230283107001

Information Security (3170720) Lab Manual

9. What is the time complexity of a brute-force attack on Caesar cipher?


 Time complexity is O(26) = O(1) (constant time), since there are only 26 keys to
try.

10. Why is modular arithmetic important in Caesar cipher?


 Modular arithmetic ensures that after shifting letters beyond Z, the alphabet wraps
around back to A. For example, shifting Z by 1 gives A.

You might also like