Vigenère & Affine Cryptanalysis Application

This project involves the development of a Python application designed to perform cryptanalysis on two classical ciphers: Vigenère and Affine. Developed within the scope of the Master's in Information Security Engineering, the tool explores vulnerabilities in these historic algorithms using various attack vectors such as Brute Force, Dictionary Attacks, and Known Plaintext Attacks.

🔐 Implemented Features

📦 Installation & Usage

🖥️ Main Interface

The application launches via main.py, presenting a stylized ASCII art menu that directs the user to specific modules for each cipher.

Main Application Menu Figure 1.1: Main application menu developed for the project.

⚔️ Attack Methodologies

The project implements three primary strategies to compromise the confidentiality of the messages.

Brute Force Attack

In this method, the attacker ("Eve") attempts every possible key combination until the correct one is found. While exhaustive, it guarantees a solution given enough time.

Brute Force Attack Diagram Figure 1.2: Conceptual illustration of a Brute Force Attack.

Known Plaintext Attack

If the attacker knows a portion of the original message (e.g., standard email greetings like "Good morning"), they can mathematically derive the key used for encryption.

Known Plaintext Attack Diagram Figure 1.3: Conceptual illustration of a Known Plaintext Attack.

📝 Vigenère Cipher Module

The Vigenère cipher is a polyalphabetic substitution method. The application allows users to generate the Vigenère table and visualize the encryption process step-by-step.

Vigenère Submenu Figure 2.2: Vigenère Cipher Submenu.

Visualization: This cipher uses a 26x26 matrix. This tool also generates the table dynamically to aid understanding.

Generated Vigenère Table Figure 2.3: Vigenère Table generated by the application.

Operations: Standard encryption and decryption. Formula: Ci = (Pi + Kj) mod 26.

Vigenère Encryption/Decryption Figure 2.4: Encryption and decryption operations.

Vigenère Cryptanalysis Results

1. Brute Force: Generates keys recursively (up to length 6) and validates against a dictionary.

Vigenère Brute Force Figure 2.5: Successfully recovering the key "BEJA".

2. Known Plaintext: Calculates the offset between the cipher and known text to reveal the key.

Vigenère Known Plaintext Figure 2.6: Recovering the key using a known text snippet.

3. Dictionary Attack: Tests keys from a wordlist, offering faster performance than brute force.

Vigenère Dictionary Attack Figure 2.7: Successful Dictionary Attack.

🧮 Affine Cipher Module

The Affine cipher is a monoalphabetic substitution system using linear algebra. Encryption function:

E(x) = (ax + b) mod 26
Decryption function:
D(x) = a-1(x - b) mod 26

Affine Submenu Figure 3.1: Affine Cipher Submenu.

Operations: Users must provide keys A (coprime to 26) and B.

Affine Encryption/Decryption Figure 3.2: Encryption and decryption using Affine.

Affine Cryptanalysis Results

1. Brute Force: Iterates through all possible values of A and B to produce a list of potential plaintexts.

Affine Brute Force Figure 3.3: Listing all possible decryptions.

2. Known Plaintext: Filters brute force results to find messages containing a specific string.

Affine Known Plaintext Figure 3.4: Pinpointing the correct message using known text.

3. Dictionary Attack: Checks decrypted outputs against the Portuguese wordlist.

Affine Dictionary Attack Figure 3.5: Successful Dictionary Attack on Affine.

Conclusion

This project successfully demonstrated how to build a Python application to analyze and break Vigenère and Affine ciphers. We explored the mathematical foundations of these systems and implemented practical attacks including Brute Force, Dictionary, and Known Plaintext.

While these classical ciphers are no longer secure for modern use, analyzing them provides essential insights into cryptanalysis. The transition from theoretical math to practical Python code highlighted the importance of computational tools in security. Future work could involve expanding the tool to support larger networks or more complex algorithms.

The security of data is crucial in increasingly complex and dynamic scenarios... continuing to explore robust encryption techniques is fundamental for the future of digital privacy.